Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] Chicken/Fishy/Steak turn into food after getting hit by fire arrow + [fixed] fireplace ingredient bug #1848

Closed
wants to merge 10 commits into from
9 changes: 7 additions & 2 deletions Entities/Common/FireScripts/FireParticle.as
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ void makeSmokeParticle(Vec2f pos, f32 gravity = -0.06f)
case 1: texture = "Entities/Effects/Sprites/SmallSmoke2.png"; break;
}

ParticleAnimated(texture, pos, Vec2f(0, 0), 0.0f, 1.0f, 5, gravity, true);
}
ParticleAnimated(texture, pos, Vec2f(0, 0), 0.0f, 1.0f, 5, gravity, true);
}

void makeBigSmokeParticle(Vec2f pos, f32 gravity = -0.06f)
{
ParticleAnimated("Entities/Effects/Sprites/LargeSmoke.png", pos, Vec2f(0, 0), 0.0f, 1.0f, 4, gravity, true);
}
47 changes: 11 additions & 36 deletions Entities/Industry/Fireplace/Fireplace.as
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Fireplace

#include "ProductionCommon.as";
#include "Requirements.as";
#include "MakeFood.as";
#include "FireParticle.as";
#include "FireCommon.as";
#include "FireplaceCommon.as";
#include "Hitters.as";
Expand All @@ -12,19 +9,12 @@ void onInit(CBlob@ this)
{
this.getCurrentScript().tickFrequency = 9;
this.getSprite().SetEmitSound("CampfireSound.ogg");
this.getSprite().SetEmitSoundPaused(false);
this.getSprite().SetAnimation("fire");
this.getSprite().SetFacingLeft(XORRandom(2) == 0);

this.SetLight(true);

this.SetLightRadius(164.0f);
this.SetLightColor(SColor(255, 255, 240, 171));

this.Tag("fire source");
//this.server_SetTimeToDie(60*3);
this.getSprite().SetZ(-20.0f);

this.addCommandID("extinguish");

SetFire(this, !this.hasTag("extinguished"));
}

void onTick(CBlob@ this)
Expand All @@ -46,12 +36,12 @@ void onTick(CBlob@ this)
}

void onCollision(CBlob@ this, CBlob@ blob, bool solid)
{
{
if (blob is null) return;

if (this.getSprite().isAnimation("fire"))
{
CBlob@ food = cookFood(blob);
CBlob@ food = CookInFireplace(blob); // MakeFood.as
if (food !is null)
{
food.setVelocity(blob.getVelocity().opMul(0.5f));
Expand All @@ -65,7 +55,7 @@ void onCollision(CBlob@ this, CBlob@ blob, bool solid)

void onInit(CSprite@ this)
{
this.SetZ(-50); //background
this.SetZ(-50.0f);

//init flame layer
CSpriteLayer@ fire = this.addSpriteLayer("fire_animation_large", "Entities/Effects/Sprites/LargeFire.png", 16, 16, -1, -1);
Expand All @@ -80,28 +70,13 @@ void onInit(CSprite@ this)
anim.AddFrame(2);
anim.AddFrame(3);
}
fire.SetVisible(true);
}
}

void Extinguish(CBlob@ this)
{
if (this.getSprite().isAnimation("nofire")) return;
CBlob@ blob = this.getBlob();

this.SetLight(false);
this.Untag("fire source");
if (blob is null) return;

this.getSprite().SetAnimation("nofire");
this.getSprite().SetEmitSoundPaused(true);
this.getSprite().PlaySound("/ExtinguishFire.ogg");

CSpriteLayer@ fire = this.getSprite().getSpriteLayer("fire_animation_large");
if (fire !is null)
{
fire.SetVisible(false);
fire.SetVisible(!blob.hasTag("extinguished"));
}

makeSmokeParticle(this.getPosition()); //*poof*
}

f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitterBlob, u8 customData)
Expand All @@ -115,4 +90,4 @@ f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitt
Ignite(this);
}
return damage;
}
}
61 changes: 49 additions & 12 deletions Entities/Industry/Fireplace/FireplaceCommon.as
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
void Ignite(CBlob@ this)

#include "FireParticle.as";

void Ignite(CBlob@ this)
{
if (this.hasTag("fire source")) return;

CSprite@ sprite = this.getSprite();

if (sprite is null) return;

if (sprite.isAnimation("fire")) return;
if (sprite !is null)
{
sprite.PlaySound("/FireFwoosh.ogg");
}

SetFire(this, true);
}

void Extinguish(CBlob@ this)
{
if (!this.hasTag("fire source")) return;

CSprite@ sprite = this.getSprite();
if (sprite !is null)
{
this.getSprite().PlaySound("/ExtinguishFire.ogg");
}

makeBigSmokeParticle(this.getPosition()); //*poof*

this.SetLight(true);
this.Tag("fire source");
SetFire(this, false);
}

void SetFire(CBlob@ this, bool fire_on)
{
CSprite@ sprite = this.getSprite();
if (sprite is null) return;

sprite.SetAnimation("fire");
sprite.SetEmitSoundPaused(false);
sprite.PlaySound("/FireFwoosh.ogg");
sprite.SetEmitSoundPaused(!fire_on);
this.SetLight(fire_on);

if (fire_on)
{
this.Tag("fire source");
this.Untag("extinguished");
sprite.SetAnimation("fire");
}
else
{
this.Untag("fire source");
this.Tag("extinguished");
sprite.SetAnimation("nofire");
}

CSpriteLayer@ fire = sprite.getSpriteLayer("fire_animation_large");
if (fire !is null)
{
fire.SetVisible(true);
fire.SetVisible(fire_on);
}
}
}
3 changes: 2 additions & 1 deletion Entities/Items/Food/EatCommon.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ u8 getHealingAmount(CBlob@ food)
void Heal(CBlob@ this, CBlob@ food)
{
bool exists = getBlobByNetworkID(food.getNetworkID()) !is null;
if (getNet().isServer() && this.hasTag("player") && this.getHealth() < this.getInitialHealth() && !food.hasTag("healed") && exists)
if (isServer() && this.hasTag("player") && this.getHealth() < this.getInitialHealth()
&& !food.hasTag("healed") && !food.hasTag("cooked") && exists)
{
CBitStream params;
params.write_u16(this.getNetworkID());
Expand Down
2 changes: 1 addition & 1 deletion Entities/Items/Food/Eatable.as
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void onCommand(CBlob@ this, u8 cmd, CBitStream@ params)
{
this.getSprite().PlaySound(this.get_string("eat sound"));

if (getNet().isServer())
if (isServer() && !this.hasTag("cooked"))
{
u16 blob_id;
if (!params.saferead_u16(blob_id)) return;
Expand Down
Binary file modified Entities/Items/Food/Food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 17 additions & 28 deletions Entities/Items/Food/MakeFood.as
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "ProductionCommon.as";

CBlob@ server_MakeFood(Vec2f atpos, const string &in name, const u8 spriteIndex)
{
if (!isServer()) return null;
Expand Down Expand Up @@ -26,47 +28,34 @@ ShopItem@ addFoodItem(CBlob@ this, const string &in foodName, const u8 spriteInd
return item;
}

CBlob@ cookFood(CBlob@ ingredient)
CBlob@ CookInFireplace(CBlob@ ingredient) // used by Fireplace.as
{
string cookedName;
u8 spriteIndex;
string n = ingredient.getName();

if (n == "fishy")
{
cookedName = "Cooked Fish";
spriteIndex = 1;
}
else if (n == "steak")
{
cookedName = "Cooked Steak";
spriteIndex = 0;
}
else if (n == "grain")
{
cookedName = "Bread";
spriteIndex = 4;
}
else if (n == "egg")
if (ingredient.hasTag("cookable in fireplace"))
{
cookedName = "Cake";
spriteIndex = 5;
return Cook(ingredient);
}
else
{
return null;
}

CBlob@ Cook(CBlob@ ingredient) // used by Chicken.as and Fishy.as
{
if (ingredient.hasTag("cooked") || ingredient.hasTag("healed") || !ingredient.exists("cooked name"))
return null;
}

CBlob@ food = server_MakeFood(ingredient.getPosition(), cookedName, spriteIndex);
string cooked_name = ingredient.get_string("cooked name");
u8 sprite_index = ingredient.get_u8("cooked sprite index");

CBlob@ food = server_MakeFood(ingredient.getPosition(), cooked_name, sprite_index);

ingredient.getSprite().PlaySound("SparkleShort.ogg");

if (food !is null)
{
ingredient.Tag("cooked");
ingredient.Sync("cooked", true);
ingredient.server_Die();
food.setVelocity(ingredient.getVelocity());
return food;
}

return null;
}
56 changes: 51 additions & 5 deletions Entities/Natural/Animals/Chicken/Chicken.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
//script for a chicken

#include "AnimalConsts.as";
#include "MakeFood.as";
#include "ArcherCommon.as";

const u8 DEFAULT_PERSONALITY = SCARED_BIT;
const int MAX_EGGS = 2; //maximum symultaneous eggs
const int MAX_EGGS = 2; //maximum simultaneous eggs
const int MAX_CHICKENS = 6;
const f32 CHICKEN_LIMIT_RADIUS = 120.0f;
const u8 cookAfterInFireTicks = 50;

int g_lastSoundPlayedTime = 0;
int g_layEggInterval = 0;
Expand Down Expand Up @@ -74,6 +77,8 @@ void onTick(CSprite@ this)
void onInit(CBlob@ this)
{
this.set_f32("bite damage", 0.25f);

this.set_u16("fire duration", 0);

//brain
this.set_u8(personality_property, DEFAULT_PERSONALITY);
Expand All @@ -90,7 +95,7 @@ void onInit(CBlob@ this)
this.Tag("flesh");

this.getShape().SetOffset(Vec2f(0, 6));

this.getCurrentScript().runFlags |= Script::tick_blob_in_proximity;
this.getCurrentScript().runProximityTag = "player";
this.getCurrentScript().runProximityRadius = 320.0f;
Expand All @@ -111,11 +116,15 @@ void onInit(CBlob@ this)
vars.slowForce.Set(1.0f, 0.0f);
vars.jumpForce.Set(0.0f, -20.0f);
vars.maxVelocity = 1.1f;

// cooking
this.set_string("cooked name", "Fried Chicken");
this.set_u8("cooked sprite index", 7);
}

bool canBePickedUp(CBlob@ this, CBlob@ byBlob)
{
return true; //maybe make a knocked out state? for loading to cata?
return true;
}

bool doesCollideWithBlob(CBlob@ this, CBlob@ blob)
Expand All @@ -125,6 +134,33 @@ bool doesCollideWithBlob(CBlob@ this, CBlob@ blob)

void onTick(CBlob@ this)
{
// cook it after it's been in fire
if (isServer())
{
CMap@ map = getMap();
Vec2f position = this.getPosition();

u16 fire_duration = this.exists("fire duration") ? this.get_u16("fire duration") : 0;

if (map.isInFire(position))
{
fire_duration++;

if (fire_duration >= cookAfterInFireTicks)
{
Cook(this); // MakeFood.as
}

this.set_u16("fire duration", fire_duration);
}
else if (fire_duration > 0)
{
fire_duration--;

this.set_u16("fire duration", fire_duration);
}
}

f32 x = this.getVelocity().x;
if (Maths::Abs(x) > 1.0f)
{
Expand Down Expand Up @@ -184,7 +220,7 @@ void onTick(CBlob@ this)
g_lastSoundPlayedTime = getGameTime();

// lay eggs
if (getNet().isServer())
if (isServer())
{
g_layEggInterval++;
if (g_layEggInterval % 13 == 0)
Expand Down Expand Up @@ -226,6 +262,17 @@ void onTick(CBlob@ this)
}
}

f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitterBlob, u8 customData)
{
if (hitterBlob.getName() == "arrow"
&& hitterBlob.get_u8("arrow type") == ArrowType::fire)
{
Cook(this); // MakeFood.as
}

return damage;
}

void onCollision(CBlob@ this, CBlob@ blob, bool solid, Vec2f normal, Vec2f point1)
{
if (blob is null)
Expand All @@ -237,4 +284,3 @@ void onCollision(CBlob@ this, CBlob@ blob, bool solid, Vec2f normal, Vec2f point
g_lastSoundPlayedTime = getGameTime();
}
}

Loading