123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110 |
- class Edible_Base : ItemBase
- {
- const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
- const string SOUND_BAKING_START = "Baking_SoundSet";
- const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
- const string SOUND_BOILING_START = "Boiling_SoundSet";
- const string SOUND_BOILING_DONE = "Boiling_Done_SoundSet";
- const string SOUND_DRYING_START = "Drying_SoundSet";
- const string SOUND_DRYING_DONE = "Drying_Done_SoundSet";
- const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
- protected bool m_MakeCookingSounds;
- protected SoundOnVehicle m_SoundCooking; //! DEPRECATED
- protected EffectSound m_SoundEffectCooking;
- protected string m_SoundPlaying;
- ref FoodStage m_FoodStage;
- protected float m_DecayTimer;
- protected float m_DecayDelta = 0.0;
- protected FoodStageType m_LastDecayStage = FoodStageType.NONE;
- protected ParticleSource m_HotVaporParticle;
-
- private CookingMethodType m_CookedByMethod;
-
- void Edible_Base()
- {
- if (HasFoodStage())
- {
- m_FoodStage = new FoodStage(this);
-
- RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
- RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
- m_SoundPlaying = "";
- m_CookedByMethod = CookingMethodType.NONE;
- RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
- RegisterNetSyncVariableBool("m_MakeCookingSounds");
- }
- }
-
- override void EEInit()
- {
- super.EEInit();
-
- UpdateVisualsEx(true); //forced init visuals, mostly for debugs and SP
- }
-
- override void EEDelete(EntityAI parent)
- {
- super.EEDelete(parent);
-
- RemoveAudio();
-
- if (m_HotVaporParticle)
- m_HotVaporParticle.Stop();
- }
-
- override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
- super.EEItemLocationChanged(oldLoc, newLoc);
- //! disable sounds (from cooking)
- if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
- {
- switch (oldLoc.GetParent().GetType())
- {
- case "FryingPan":
- case "Pot":
- case "Cauldron":
- case "SharpWoodenStick":
- MakeSoundsOnClient(false);
- break;
- }
-
- //! check for DirectCooking slot name
- if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
- {
- MakeSoundsOnClient(false);
- }
- }
-
- if (oldLoc.IsValid())
- ResetCookingTime();
-
- if (CanHaveTemperature())
- UpdateVaporParticle();
- }
- void UpdateVisualsEx(bool forced = false)
- {
- if (GetFoodStage())
- GetFoodStage().UpdateVisualsEx(forced);
- }
-
- bool Consume(float amount, PlayerBase consumer)
- {
- AddQuantity(-amount, false, false);
- OnConsume(amount, consumer);
- return true;
- }
-
- void OnConsume(float amount, PlayerBase consumer)
- {
- if (GetTemperature() > PlayerConstants.CONSUMPTION_DAMAGE_TEMP_THRESHOLD)
- {
- consumer.ProcessDirectDamage(DamageType.CUSTOM, this, "", "EnviroDmg", "0 0 0", PlayerConstants.CONSUMPTION_DAMAGE_PER_BITE);
- }
- }
-
- //! Filter agents from the item (override on higher implementations)
- int FilterAgents(int agentsIn)
- {
- int foodStageType;
- FoodStage foodStage = GetFoodStage();
- if (foodStage)
- foodStageType = foodStage.GetFoodStageType();
- //! if no per FoodStage/Nutrition override is set, remove possible Food Poisoning to prevent double punishment from Bloody Hands
- NutritionalProfile nutritionalProfile = GetNutritionalProfile(this, ClassName(), foodStageType);
- if ((agentsIn & eAgents.SALMONELLA == eAgents.SALMONELLA) && (nutritionalProfile.m_Agents == 0 || nutritionalProfile.m_AgentsPerDigest == 0))
- agentsIn &= ~eAgents.FOOD_POISON;
- return agentsIn;
- }
-
- //food staging
- override bool CanBeCooked()
- {
- return false;
- }
-
- override bool CanBeCookedOnStick()
- {
- return false;
- }
-
- override float GetTemperatureFreezeTime()
- {
- if (GetFoodStage())
- {
- switch (m_FoodStage.GetFoodStageType())
- {
- case FoodStageType.DRIED:
- return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_DRIED;
-
- case FoodStageType.BURNED:
- return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_BURNED;
-
- default:
- return super.GetTemperatureFreezeTime();
- }
- }
-
- return super.GetTemperatureFreezeTime();
- }
-
- override float GetTemperatureThawTime()
- {
- if (GetFoodStage())
- {
- switch (m_FoodStage.GetFoodStageType())
- {
- case FoodStageType.DRIED:
- return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_DRIED;
-
- case FoodStageType.BURNED:
- return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_BURNED;
-
- default:
- return super.GetTemperatureThawTime();
- }
- }
-
- return super.GetTemperatureThawTime();
- }
-
- override bool CanItemOverheat()
- {
- return super.CanItemOverheat() && (!GetFoodStage() || (IsFoodBurned() || !GetFoodStage().CanTransitionToFoodStageType(FoodStageType.BURNED))); //for foodstaged items - either is burned, or it can't get burned
- }
-
- //================================================================
- // SYNCHRONIZATION
- //================================================================
- void Synchronize()
- {
- SetSynchDirty();
- }
-
- override void OnVariablesSynchronized()
- {
- super.OnVariablesSynchronized();
-
- //UpdateVisualsEx(); //performed on client only
-
- //update audio
- if (m_MakeCookingSounds)
- {
- RefreshAudio();
- }
- else
- {
- RemoveAudio();
- }
-
- if (CanHaveTemperature())
- UpdateVaporParticle();
- }
- //================================================================
- // AUDIO EFFECTS (WHEN ON DCS)
- //================================================================
- void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod = CookingMethodType.NONE)
- {
- m_MakeCookingSounds = soundstate;
- m_CookedByMethod = cookingMethod;
- Synchronize();
- }
- protected void RefreshAudio()
- {
- string soundName = "";
-
- FoodStageType currentFoodStage = GetFoodStageType();
- FoodStageType nextFoodStage = GetNextFoodStageType(m_CookedByMethod);
- if (currentFoodStage == FoodStageType.BURNED)
- {
- soundName = SOUND_BURNING_DONE;
- }
- else
- {
- switch (m_CookedByMethod)
- {
- case CookingMethodType.BAKING:
- {
- if (nextFoodStage == FoodStageType.BAKED)
- soundName = SOUND_BAKING_START;
- else if (currentFoodStage == FoodStageType.BAKED)
- soundName = SOUND_BAKING_DONE;
- else
- soundName = "";
- break;
- }
-
- case CookingMethodType.BOILING:
- {
- if (nextFoodStage == FoodStageType.BOILED)
- soundName = SOUND_BOILING_START;
- else if (currentFoodStage == FoodStageType.BOILED)
- soundName = SOUND_BOILING_DONE;
- else
- soundName = "";
- break;
- }
-
- case CookingMethodType.DRYING:
- {
- if (nextFoodStage == FoodStageType.DRIED)
- soundName = SOUND_DRYING_START;
- else if (currentFoodStage == FoodStageType.DRIED)
- soundName = SOUND_DRYING_DONE;
- else
- soundName = "";
- break;
- }
-
- default:
- soundName = "";
- break;
- }
-
- if (nextFoodStage == FoodStageType.BURNED)
- {
- if (soundName == "") //on 'bad' transitions only, indicates bad outcome
- {
- soundName = SOUND_BURNING_DONE;
- }
- else // pre-emptive burning sounds replace regular ones
- {
- array<float> nextStageProperties = new array<float>();
- nextStageProperties = FoodStage.GetAllCookingPropertiesForStage(nextFoodStage, null, GetType());
- float nextStageTime = nextStageProperties.Get(eCookingPropertyIndices.COOK_TIME);
- float progress01 = GetCookingTime() / nextStageTime;
- if (progress01 > Cooking.BURNING_WARNING_THRESHOLD)
- {
- soundName = SOUND_BURNING_DONE;
- }
- }
- }
- }
-
- SoundCookingStart(soundName);
- }
- protected void RemoveAudio()
- {
- m_MakeCookingSounds = false;
- SoundCookingStop();
- }
- //================================================================
- // SERIALIZATION
- //================================================================
- override void OnStoreSave(ParamsWriteContext ctx)
- {
- super.OnStoreSave(ctx);
- if (GetFoodStage())
- {
- GetFoodStage().OnStoreSave(ctx);
- }
-
- // food decay
- ctx.Write(m_DecayTimer);
- ctx.Write(m_LastDecayStage);
- }
-
- override bool OnStoreLoad(ParamsReadContext ctx, int version)
- {
- if (!super.OnStoreLoad(ctx, version))
- return false;
- if (GetFoodStage())
- {
- if (!GetFoodStage().OnStoreLoad(ctx, version))
- return false;
- }
-
- if (version >= 115)
- {
- if (!ctx.Read(m_DecayTimer))
- {
- m_DecayTimer = 0.0;
- return false;
- }
- if (!ctx.Read(m_LastDecayStage))
- {
- m_LastDecayStage = FoodStageType.NONE;
- return false;
- }
- }
-
- UpdateVisualsEx(true); //forced init visuals
- Synchronize();
-
- return true;
- }
-
- override void AfterStoreLoad()
- {
- super.AfterStoreLoad();
-
- Synchronize();
- }
- //get food stage
- override FoodStage GetFoodStage()
- {
- return m_FoodStage;
- }
-
- //food types
- override bool IsMeat()
- {
- return false;
- }
-
- override bool IsCorpse()
- {
- return false;
- }
-
- override bool IsFruit()
- {
- return false;
- }
-
- override bool IsMushroom()
- {
- return false;
- }
-
- //================================================================
- // NUTRITIONAL VALUES
- //================================================================
- //food properties
- static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetFullnessIndex(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetFloat( class_path + " fullnessIndex" );
- }
-
- static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetEnergy(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetEnergy(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetFloat( class_path + " energy" );
- }
-
- static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetWater(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetWater(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetFloat( class_path + " water" );
- }
-
- static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetNutritionalIndex(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetFloat( class_path + " nutritionalIndex" );
-
- }
-
- static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetToxicity(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetToxicity(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetFloat( class_path + " toxicity" );
- }
-
- static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetAgents(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetAgents(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetInt( class_path + " agents" );
- }
-
- static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
- {
- Edible_Base food_item = Edible_Base.Cast(item);
- if (food_item && food_item.GetFoodStage())
- {
- return FoodStage.GetDigestibility(food_item.GetFoodStage());
- }
- else if (classname != "" && food_stage)
- {
- return FoodStage.GetDigestibility(null, food_stage, classname);
- }
- string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
- return GetGame().ConfigGetInt( class_path + " digestibility" );
- }
-
- static float GetAgentsPerDigest(ItemBase item, string className = "", int foodStage = 0)
- {
- Edible_Base foodItem = Edible_Base.Cast(item);
- if (foodItem && foodItem.GetFoodStage())
- {
- return FoodStage.GetAgentsPerDigest(foodItem.GetFoodStage());
- }
- else if (className != "" && foodStage)
- {
- return FoodStage.GetAgentsPerDigest(null, foodStage, className);
- }
- string classPath = string.Format("cfgVehicles %1 Nutrition", className);
- return GetGame().ConfigGetInt(classPath + " agentsPerDigest");
- }
-
- static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname = "", int food_stage = 0)
- {
- NutritionalProfile profile = new NutritionalProfile();
- profile.m_Energy = GetFoodEnergy(item, classname, food_stage);
- profile.m_WaterContent = GetFoodWater(item, classname, food_stage);
- profile.m_NutritionalIndex = GetFoodNutritionalIndex(item, classname, food_stage);
- profile.m_FullnessIndex = GetFoodTotalVolume(item, classname, food_stage);
- profile.m_Toxicity = GetFoodToxicity(item, classname, food_stage);
- profile.m_Agents = GetFoodAgents(item, classname, food_stage);
- profile.m_Digestibility = GetFoodDigestibility(item, classname, food_stage);
- profile.m_AgentsPerDigest = GetAgentsPerDigest(item, classname, food_stage);
-
- return profile;
- }
-
- //================================================================
- // FOOD STAGING
- //================================================================
- FoodStageType GetFoodStageType()
- {
- return GetFoodStage().GetFoodStageType();
- }
-
- //food stage states
- bool IsFoodRaw()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodRaw();
- }
-
- return false;
- }
- bool IsFoodBaked()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodBaked();
- }
-
- return false;
- }
-
- bool IsFoodBoiled()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodBoiled();
- }
-
- return false;
- }
-
- bool IsFoodDried()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodDried();
- }
-
- return false;
- }
-
- bool IsFoodBurned()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodBurned();
- }
-
- return false;
- }
-
- bool IsFoodRotten()
- {
- if ( GetFoodStage() )
- {
- return GetFoodStage().IsFoodRotten();
- }
-
- return false;
- }
-
- //food stage change
- void ChangeFoodStage( FoodStageType new_food_stage_type )
- {
- GetFoodStage().ChangeFoodStage( new_food_stage_type );
- }
-
- FoodStageType GetNextFoodStageType( CookingMethodType cooking_method )
- {
- return GetFoodStage().GetNextFoodStageType( cooking_method );
- }
-
- string GetFoodStageName( FoodStageType food_stage_type )
- {
- return GetFoodStage().GetFoodStageName( food_stage_type );
- }
-
- bool CanChangeToNewStage( CookingMethodType cooking_method )
- {
- return GetFoodStage().CanChangeToNewStage( cooking_method );
- }
-
- //Use this to receive food stage from another Edible_Base
- void TransferFoodStage( notnull Edible_Base source )
- {
- if ( !source.GetFoodStage())
- return;
- m_LastDecayStage = source.GetLastDecayStage();
- ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
- m_DecayTimer = source.GetDecayTimer();
- m_DecayDelta = source.GetDecayDelta();
- }
-
- //! called on server
- void OnFoodStageChange(FoodStageType stageOld, FoodStageType stageNew)
- {
- HandleFoodStageChangeAgents(stageOld,stageNew);
- UpdateVisualsEx(); //performed on server only
- }
-
- //! removes select agents on foodstage transitions
- void HandleFoodStageChangeAgents(FoodStageType stageOld, FoodStageType stageNew)
- {
- switch (stageNew)
- {
- case FoodStageType.BAKED:
- case FoodStageType.BOILED:
- case FoodStageType.DRIED:
- RemoveAllAgentsExcept(eAgents.BRAIN|eAgents.HEAVYMETAL);
- break;
-
- case FoodStageType.BURNED:
- RemoveAllAgentsExcept(eAgents.BRAIN|eAgents.HEAVYMETAL);
- break;
- }
- }
-
- //================================================================
- // COOKING
- //================================================================
- //cooking time
- float GetCookingTime()
- {
- return GetFoodStage().GetCookingTime();
- }
-
- void SetCookingTime( float time )
- {
- GetFoodStage().SetCookingTime( time );
-
- //synchronize when calling on server
- Synchronize();
- }
-
- void ResetCookingTime()
- {
- if (GetFoodStage())
- {
- GetFoodStage().SetCookingTime(0);
- Synchronize();
- }
- }
-
- //replace edible with new item (opening cans)
- void ReplaceEdibleWithNew( string typeName )
- {
- PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
- if (player)
- {
- ReplaceEdibleWithNewLambda lambda = new ReplaceEdibleWithNewLambda(this, typeName, player);
- player.ServerReplaceItemInHandsWithNew(lambda);
- }
- else
- Error("ReplaceEdibleWithNew - cannot use edible without player");
- }
-
- int GetConsumptionPenaltyContext()
- {
- return EConsumptionPenaltyContext.DRINK|EConsumptionPenaltyContext.EAT;
- }
- override void SetActions()
- {
- super.SetActions();
- AddAction(ActionAttach);
- AddAction(ActionDetach);
- }
- protected void SoundCookingStart(string sound_name)
- {
- #ifndef SERVER
- if (m_SoundPlaying != sound_name)
- {
- SoundCookingStop();
- m_SoundEffectCooking = SEffectManager.PlaySound(sound_name, GetPosition(), 0, 0, true);
- m_SoundPlaying = sound_name;
- }
- #endif
- }
- protected void SoundCookingStop()
- {
- #ifndef SERVER
- if (m_SoundEffectCooking)
- {
- m_SoundEffectCooking.Stop();
- m_SoundEffectCooking = null;
- m_SoundPlaying = "";
- }
- #endif
- }
-
- override bool CanDecay()
- {
- return false;
- }
-
- override bool CanProcessDecay()
- {
- return !GetIsFrozen() && ( GetFoodStageType() != FoodStageType.ROTTEN );
- }
-
- override void ProcessDecay( float delta, bool hasRootAsPlayer )
- {
- m_DecayDelta = 0.0;
-
- delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
- m_DecayDelta += ( 1 + ( 1 - GetHealth01( "", "" ) ) );
- if ( hasRootAsPlayer )
- m_DecayDelta += GameConstants.DECAY_RATE_ON_PLAYER;
-
- /*Print( "-------------------------" );
- Print( this );
- Print( m_DecayTimer );
- Print( m_DecayDelta );
- Print( m_LastDecayStage );*/
-
- if ( IsFruit() || IsMushroom() )
- {
- // fruit, vegetables and mushrooms
- if ( m_LastDecayStage != GetFoodStageType() )
- {
- switch ( GetFoodStageType() )
- {
- case FoodStageType.RAW:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.RAW;
- break;
-
- case FoodStageType.BOILED:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_BOILED_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BOILED_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.BOILED;
- break;
-
- case FoodStageType.BAKED:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_BAKED_FRVG + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BAKED_FRVG * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.BAKED;
- break;
-
- case FoodStageType.DRIED:
- case FoodStageType.BURNED:
- case FoodStageType.ROTTEN:
- default:
- m_DecayTimer = -1;
- m_LastDecayStage = FoodStageType.NONE;
- return;
- }
-
- //m_DecayTimer = m_DecayTimer / 1000.0;
- }
-
- m_DecayTimer -= ( delta * m_DecayDelta );
-
- if ( m_DecayTimer <= 0 )
- {
- if ( m_LastDecayStage != FoodStageType.NONE )
- {
- // switch to decayed stage
- if ( ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
- {
- ChangeFoodStage( FoodStageType.ROTTEN );
- }
- if ( m_LastDecayStage == FoodStageType.RAW )
- {
- int rng = Math.RandomIntInclusive( 0, 100 );
- if ( rng > GameConstants.DECAY_FOOD_FRVG_DRIED_CHANCE )
- {
- ChangeFoodStage( FoodStageType.ROTTEN );
- }
- else
- {
- if ( CanChangeToNewStage( FoodStageType.DRIED ) )
- {
- ChangeFoodStage( FoodStageType.DRIED );
- }
- else
- {
- ChangeFoodStage( FoodStageType.ROTTEN );
- }
- }
- }
- }
- }
- }
- else if ( IsMeat() )
- {
- // meat
- if ( m_LastDecayStage != GetFoodStageType() )
- {
- switch ( GetFoodStageType() )
- {
- case FoodStageType.RAW:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.RAW;
- break;
-
- case FoodStageType.BOILED:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_BOILED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BOILED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.BOILED;
- break;
-
- case FoodStageType.BAKED:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_BAKED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_BAKED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.BAKED;
- break;
-
- case FoodStageType.DRIED:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_DRIED_MEAT + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_DRIED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.DRIED;
- break;
- case FoodStageType.BURNED:
- case FoodStageType.ROTTEN:
- default:
- m_DecayTimer = -1;
- m_LastDecayStage = FoodStageType.NONE;
- return;
- }
- }
-
- m_DecayTimer -= ( delta * m_DecayDelta );
-
- if ( m_DecayTimer <= 0 )
- {
- if ( m_LastDecayStage != FoodStageType.NONE )
- {
- // switch to decayed stage
- if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
- {
- ChangeFoodStage( FoodStageType.ROTTEN );
- }
- }
- }
- }
- else if ( IsCorpse() )
- {
- // corpse
- if ( m_LastDecayStage != GetFoodStageType() )
- {
- switch ( GetFoodStageType() )
- {
- case FoodStageType.RAW:
- m_DecayTimer = ( GameConstants.DECAY_FOOD_RAW_CORPSE + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_RAW_CORPSE * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.RAW;
- break;
- case FoodStageType.BURNED:
- case FoodStageType.ROTTEN:
- default:
- m_DecayTimer = -1;
- m_LastDecayStage = FoodStageType.NONE;
- return;
- }
- }
-
- m_DecayTimer -= ( delta * m_DecayDelta );
-
- if ( m_DecayTimer <= 0 )
- {
- if ( m_LastDecayStage != FoodStageType.NONE )
- {
- // switch to decayed stage
- if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
- {
- ChangeFoodStage( FoodStageType.ROTTEN );
- }
- }
- }
- }
- else
- {
- // opened cans
- m_DecayTimer -= ( delta * m_DecayDelta );
- if ( ( m_DecayTimer <= 0 ) && ( m_LastDecayStage == FoodStageType.NONE ) )
- {
- m_DecayTimer = ( GameConstants.DECAY_FOOD_CAN_OPEN + ( Math.RandomFloat01() * ( GameConstants.DECAY_FOOD_DRIED_MEAT * ( GameConstants.DECAY_TIMER_RANDOM_PERCENTAGE / 100.0 ) ) ) );
- m_LastDecayStage = FoodStageType.RAW;
- //m_DecayTimer = m_DecayTimer / 1000.0;
- }
- else
- {
- if ( m_DecayTimer <= 0 )
- {
- InsertAgent(eAgents.FOOD_POISON, 1);
- m_DecayTimer = -1;
- }
- }
- }
- }
-
- protected void UpdateVaporParticle()
- {
- if (GetGame().IsDedicatedServer())
- return;
-
- if (m_VarTemperature >= GameConstants.STATE_HOT_LVL_TWO && !m_HotVaporParticle)
- {
- InventoryLocation invLoc = new InventoryLocation();
- GetInventory().GetCurrentInventoryLocation(invLoc);
- if (invLoc && (invLoc.GetType() == InventoryLocationType.GROUND || invLoc.GetType() == InventoryLocationType.HANDS || invLoc.GetType() == InventoryLocationType.ATTACHMENT))
- {
- ParticleManager ptcMgr = ParticleManager.GetInstance();
- if (ptcMgr)
- {
- m_HotVaporParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.ITEM_HOT_VAPOR, this);
- m_HotVaporParticle.SetParticleParam(EmitorParam.SIZE, 0.3);
- m_HotVaporParticle.SetParticleParam(EmitorParam.BIRTH_RATE, 10);
- m_HotVaporParticle.SetParticleAutoDestroyFlags(ParticleAutoDestroyFlags.ON_STOP);
- }
- }
- }
- else if (m_HotVaporParticle)
- {
- if (m_VarTemperature <= GameConstants.STATE_HOT_LVL_TWO)
- {
- m_HotVaporParticle.Stop();
- m_HotVaporParticle = null;
- return;
- }
-
- InventoryLocation inventoryLoc = new InventoryLocation();
- GetInventory().GetCurrentInventoryLocation(inventoryLoc);
- if (invLoc && (invLoc.GetType() != InventoryLocationType.GROUND && invLoc.GetType() != InventoryLocationType.HANDS))
- {
- m_HotVaporParticle.Stop();
- m_HotVaporParticle = null;
- }
- }
- }
-
- override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
- {
- super.GetDebugActions(outputList);
-
- if (GetFoodStage())
- {
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_NUTRITIONS_DATA, "Food Nutritions Data", FadeColors.WHITE));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
- }
- }
-
- override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
- {
- super.OnAction(action_id, player, ctx);
-
- if ( GetGame().IsServer() )
- {
- if ( action_id == EActions.FOOD_STAGE_PREV )
- {
- int food_stage_prev = GetFoodStageType() - 1;
- if (food_stage_prev <= 0)
- {
- food_stage_prev = FoodStageType.COUNT - 1;
- }
- ChangeFoodStage(food_stage_prev);
- return true;
- }
- else if ( action_id == EActions.FOOD_STAGE_NEXT )
- {
- int food_stage_next = GetFoodStageType() + 1;
- if (food_stage_next >= FoodStageType.COUNT )
- {
- food_stage_next = FoodStageType.RAW;
- }
- ChangeFoodStage(food_stage_next);
- return true;
- }
-
- }
-
- #ifdef DIAG_DEVELOPER
- if (action_id == EActions.FOOD_NUTRITIONS_DATA)
- {
- PrintNutritionsData();
- return true;
- }
- #endif
- return false;
- }
-
- override string GetDebugText()
- {
- string debug_output;
- debug_output = super.GetDebugText();
-
- debug_output+="m_CookedByMethod:"+m_CookedByMethod+"\n";
- debug_output+="m_MakeCookingSounds:"+m_MakeCookingSounds+"\n";
- return debug_output;
- }
- //================================================================
- // GENERAL GETTERS
- //================================================================
-
- override float GetBaitEffectivity()
- {
- float ret = super.GetBaitEffectivity();
-
- if (IsFoodRotten())
- {
- ret *= 0.5;
- }
-
- return ret;
- }
-
- float GetDecayTimer()
- {
- return m_DecayTimer;
- }
-
- float GetDecayDelta()
- {
- return m_DecayDelta;
- }
-
- FoodStageType GetLastDecayStage()
- {
- return m_LastDecayStage;
- }
-
- #ifdef DIAG_DEVELOPER
- private void PrintNutritionsData()
- {
- string nutritionsData = "";
-
- FoodStage stage = GetFoodStage();
- FoodStageType stageType = stage.GetFoodStageType();
- NutritionalProfile profile = GetNutritionalProfile(this, ClassName(), stageType);
- if (profile)
- {
- nutritionsData = string.Format("Item: %1\n\n", this);
- nutritionsData += string.Format("Stage name: %1\n", GetFoodStageName(stageType));
- nutritionsData += string.Format("Energy: %1\n", profile.m_Energy);
- nutritionsData += string.Format("Water content: %1\n", profile.m_WaterContent);
- nutritionsData += string.Format("Nutritional index: %1\n", profile.m_NutritionalIndex);
- nutritionsData += string.Format("Fullness index: %1\n", profile.m_FullnessIndex);
- nutritionsData += string.Format("Toxicity (obsolete): %1\n", profile.m_Toxicity);
- nutritionsData += string.Format("Digestibility: %1\n", profile.m_Digestibility);
- if (profile.IsLiquid())
- nutritionsData += string.Format("Liquid type: %1\n", profile.m_LiquidClassname);
-
- nutritionsData += string.Format("Agents: %1\n", profile.m_Agents);
- nutritionsData += string.Format("Agents per consume: %1\n", profile.m_AgentsPerDigest);
- }
-
- nutritionsData += "-----\n";
-
- Debug.Log(nutritionsData);
- }
- #endif
-
- //////////////////////////////////////////
- //DEPRECATED
- //////////////////////////////////////////
- void UpdateVisuals()
- {
- UpdateVisualsEx();
- }
- }
- class ReplaceEdibleWithNewLambda : TurnItemIntoItemLambda
- {
- void ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player) { }
- };
|