DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ OnConsume()

void ReplaceEdibleWithNewLambda::OnConsume ( float amount,
PlayerBase consumer )
private

См. определение в файле Edible_Base.c строка 1210

1210 : ItemBase
1211{
1212 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1213
1214 const string SOUND_BAKING_START = "Baking_SoundSet";
1215 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1216 const string SOUND_BOILING_START = "Boiling_SoundSet";
1217 const string SOUND_BOILING_DONE = "Boiling_Done_SoundSet";
1218 const string SOUND_DRYING_START = "Drying_SoundSet";
1219 const string SOUND_DRYING_DONE = "Drying_Done_SoundSet";
1220 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1221
1222 protected bool m_MakeCookingSounds;
1223 protected SoundOnVehicle m_SoundCooking;
1225 protected string m_SoundPlaying;
1226 ref FoodStage m_FoodStage;
1227 protected float m_DecayTimer;
1228 protected float m_DecayDelta = 0.0;
1231
1233
1234 void Edible_Base()
1235 {
1236 if (HasFoodStage())
1237 {
1238 m_FoodStage = new FoodStage(this);
1239
1240 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1241 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1242
1243 m_SoundPlaying = "";
1245 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1246 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1247 }
1248 }
1249
1250 override void EEInit()
1251 {
1252 super.EEInit();
1253
1254 UpdateVisualsEx(true); //forced init visuals, mostly for debugs and SP
1255 }
1256
1257 override void EEDelete(EntityAI parent)
1258 {
1259 super.EEDelete(parent);
1260
1261 RemoveAudio();
1262
1264 m_HotVaporParticle.Stop();
1265 }
1266
1267 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
1268 {
1269 super.EEItemLocationChanged(oldLoc, newLoc);
1270
1272 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1273 {
1274 switch (oldLoc.GetParent().GetType())
1275 {
1276 case "FryingPan":
1277 case "Pot":
1278 case "Cauldron":
1279 case "SharpWoodenStick":
1280 MakeSoundsOnClient(false);
1281 break;
1282 }
1283
1285 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1286 {
1287 MakeSoundsOnClient(false);
1288 }
1289 }
1290
1291 if (oldLoc.IsValid())
1293
1294 if (CanHaveTemperature())
1296 }
1297
1298 void UpdateVisualsEx(bool forced = false)
1299 {
1300 if (GetFoodStage())
1301 GetFoodStage().UpdateVisualsEx(forced);
1302 }
1303
1304 bool Consume(float amount, PlayerBase consumer)
1305 {
1306 AddQuantity(-amount, false, false);
1307 OnConsume(amount, consumer);
1308
1309 return true;
1310 }
1311
1312 void OnConsume(float amount, PlayerBase consumer)
1313 {
1315 {
1316 consumer.ProcessDirectDamage(DamageType.CUSTOM, this, "", "EnviroDmg", "0 0 0", PlayerConstants.CONSUMPTION_DAMAGE_PER_BITE);
1317 }
1318 }
1319
1321 int FilterAgents(int agentsIn)
1322 {
1323 int foodStageType;
1324
1325 FoodStage foodStage = GetFoodStage();
1326 if (foodStage)
1327 foodStageType = foodStage.GetFoodStageType();
1328
1330 NutritionalProfile nutritionalProfile = GetNutritionalProfile(this, ClassName(), foodStageType);
1331 if ((agentsIn & eAgents.SALMONELLA == eAgents.SALMONELLA) && (nutritionalProfile.m_Agents == 0 || nutritionalProfile.m_AgentsPerDigest == 0))
1332 agentsIn &= ~eAgents.FOOD_POISON;
1333
1334 return agentsIn;
1335 }
1336
1337 //food staging
1338 override bool CanBeCooked()
1339 {
1340 return false;
1341 }
1342
1343 override bool CanBeCookedOnStick()
1344 {
1345 return false;
1346 }
1347
1348 override float GetTemperatureFreezeTime()
1349 {
1350 if (GetFoodStage())
1351 {
1352 switch (m_FoodStage.GetFoodStageType())
1353 {
1354 case FoodStageType.DRIED:
1355 return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_DRIED;
1356
1357 case FoodStageType.BURNED:
1358 return super.GetTemperatureFreezeTime() * GameConstants.TEMPERATURE_FREEZE_TIME_COEF_BURNED;
1359
1360 default:
1361 return super.GetTemperatureFreezeTime();
1362 }
1363 }
1364
1365 return super.GetTemperatureFreezeTime();
1366 }
1367
1368 override float GetTemperatureThawTime()
1369 {
1370 if (GetFoodStage())
1371 {
1372 switch (m_FoodStage.GetFoodStageType())
1373 {
1374 case FoodStageType.DRIED:
1375 return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_DRIED;
1376
1377 case FoodStageType.BURNED:
1378 return super.GetTemperatureThawTime() * GameConstants.TEMPERATURE_THAW_TIME_COEF_BURNED;
1379
1380 default:
1381 return super.GetTemperatureThawTime();
1382 }
1383 }
1384
1385 return super.GetTemperatureThawTime();
1386 }
1387
1388 override bool CanItemOverheat()
1389 {
1390 return super.CanItemOverheat() && (!GetFoodStage() || (IsFoodBurned() || !GetFoodStage().CanTransitionToFoodStageType(FoodStageType.BURNED))); //for foodstaged items - either is burned, or it can't get burned
1391 }
1392
1393 //================================================================
1394 // SYNCHRONIZATION
1395 //================================================================
1396 void Synchronize()
1397 {
1398 SetSynchDirty();
1399 }
1400
1401 override void OnVariablesSynchronized()
1402 {
1403 super.OnVariablesSynchronized();
1404
1405 //UpdateVisualsEx(); //performed on client only
1406
1407 //update audio
1409 {
1410 RefreshAudio();
1411 }
1412 else
1413 {
1414 RemoveAudio();
1415 }
1416
1417 if (CanHaveTemperature())
1419 }
1420
1421 //================================================================
1422 // AUDIO EFFECTS (WHEN ON DCS)
1423 //================================================================
1424 void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod = CookingMethodType.NONE)
1425 {
1426 m_MakeCookingSounds = soundstate;
1427 m_CookedByMethod = cookingMethod;
1428
1429 Synchronize();
1430 }
1431
1432 protected void RefreshAudio()
1433 {
1434 string soundName = "";
1435
1436 FoodStageType currentFoodStage = GetFoodStageType();
1438
1439 if (currentFoodStage == FoodStageType.BURNED)
1440 {
1441 soundName = SOUND_BURNING_DONE;
1442 }
1443 else
1444 {
1445 switch (m_CookedByMethod)
1446 {
1447 case CookingMethodType.BAKING:
1448 {
1449 if (nextFoodStage == FoodStageType.BAKED)
1450 soundName = SOUND_BAKING_START;
1451 else if (currentFoodStage == FoodStageType.BAKED)
1452 soundName = SOUND_BAKING_DONE;
1453 else
1454 soundName = "";
1455 break;
1456 }
1457
1458 case CookingMethodType.BOILING:
1459 {
1460 if (nextFoodStage == FoodStageType.BOILED)
1461 soundName = SOUND_BOILING_START;
1462 else if (currentFoodStage == FoodStageType.BOILED)
1463 soundName = SOUND_BOILING_DONE;
1464 else
1465 soundName = "";
1466 break;
1467 }
1468
1469 case CookingMethodType.DRYING:
1470 {
1471 if (nextFoodStage == FoodStageType.DRIED)
1472 soundName = SOUND_DRYING_START;
1473 else if (currentFoodStage == FoodStageType.DRIED)
1474 soundName = SOUND_DRYING_DONE;
1475 else
1476 soundName = "";
1477 break;
1478 }
1479
1480 default:
1481 soundName = "";
1482 break;
1483 }
1484
1485 if (nextFoodStage == FoodStageType.BURNED)
1486 {
1487 if (soundName == "") //on 'bad' transitions only, indicates bad outcome
1488 {
1489 soundName = SOUND_BURNING_DONE;
1490 }
1491 else // pre-emptive burning sounds replace regular ones
1492 {
1493 array<float> nextStageProperties = new array<float>();
1494 nextStageProperties = FoodStage.GetAllCookingPropertiesForStage(nextFoodStage, null, GetType());
1495 float nextStageTime = nextStageProperties.Get(eCookingPropertyIndices.COOK_TIME);
1496 float progress01 = GetCookingTime() / nextStageTime;
1497 if (progress01 > Cooking.BURNING_WARNING_THRESHOLD)
1498 {
1499 soundName = SOUND_BURNING_DONE;
1500 }
1501 }
1502 }
1503 }
1504
1505 SoundCookingStart(soundName);
1506 }
1507
1508 protected void RemoveAudio()
1509 {
1510 m_MakeCookingSounds = false;
1512 }
1513
1514 //================================================================
1515 // SERIALIZATION
1516 //================================================================
1517 override void OnStoreSave(ParamsWriteContext ctx)
1518 {
1519 super.OnStoreSave(ctx);
1520
1521 if (GetFoodStage())
1522 {
1523 GetFoodStage().OnStoreSave(ctx);
1524 }
1525
1526 // food decay
1527 ctx.Write(m_DecayTimer);
1529 }
1530
1531 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1532 {
1533 if (!super.OnStoreLoad(ctx, version))
1534 return false;
1535
1536 if (GetFoodStage())
1537 {
1538 if (!GetFoodStage().OnStoreLoad(ctx, version))
1539 return false;
1540 }
1541
1542 if (version >= 115)
1543 {
1544 if (!ctx.Read(m_DecayTimer))
1545 {
1546 m_DecayTimer = 0.0;
1547 return false;
1548 }
1549 if (!ctx.Read(m_LastDecayStage))
1550 {
1552 return false;
1553 }
1554 }
1555
1556 UpdateVisualsEx(true); //forced init visuals
1557 Synchronize();
1558
1559 return true;
1560 }
1561
1562 override void AfterStoreLoad()
1563 {
1564 super.AfterStoreLoad();
1565
1566 Synchronize();
1567 }
1568
1569 //get food stage
1570 override FoodStage GetFoodStage()
1571 {
1572 return m_FoodStage;
1573 }
1574
1575 //food types
1576 override bool IsMeat()
1577 {
1578 return false;
1579 }
1580
1581 override bool IsCorpse()
1582 {
1583 return false;
1584 }
1585
1586 override bool IsFruit()
1587 {
1588 return false;
1589 }
1590
1591 override bool IsMushroom()
1592 {
1593 return false;
1594 }
1595
1596 //================================================================
1597 // NUTRITIONAL VALUES
1598 //================================================================
1599 //food properties
1600 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1601 {
1602 Edible_Base food_item = Edible_Base.Cast(item);
1603 if (food_item && food_item.GetFoodStage())
1604 {
1605 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1606 }
1607 else if (classname != "" && food_stage)
1608 {
1609 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1610 }
1611 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1612 return GetGame().ConfigGetFloat( class_path + " fullnessIndex" );
1613
1614 }
1615
1616 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1617 {
1618 Edible_Base food_item = Edible_Base.Cast(item);
1619 if (food_item && food_item.GetFoodStage())
1620 {
1621 return FoodStage.GetEnergy(food_item.GetFoodStage());
1622 }
1623 else if (classname != "" && food_stage)
1624 {
1625 return FoodStage.GetEnergy(null, food_stage, classname);
1626 }
1627 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1628 return GetGame().ConfigGetFloat( class_path + " energy" );
1629 }
1630
1631 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1632 {
1633 Edible_Base food_item = Edible_Base.Cast(item);
1634 if (food_item && food_item.GetFoodStage())
1635 {
1636 return FoodStage.GetWater(food_item.GetFoodStage());
1637 }
1638 else if (classname != "" && food_stage)
1639 {
1640 return FoodStage.GetWater(null, food_stage, classname);
1641 }
1642 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1643 return GetGame().ConfigGetFloat( class_path + " water" );
1644 }
1645
1646 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1647 {
1648 Edible_Base food_item = Edible_Base.Cast(item);
1649 if (food_item && food_item.GetFoodStage())
1650 {
1651 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1652 }
1653 else if (classname != "" && food_stage)
1654 {
1655 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1656 }
1657 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1658 return GetGame().ConfigGetFloat( class_path + " nutritionalIndex" );
1659
1660 }
1661
1662 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1663 {
1664 Edible_Base food_item = Edible_Base.Cast(item);
1665 if (food_item && food_item.GetFoodStage())
1666 {
1667 return FoodStage.GetToxicity(food_item.GetFoodStage());
1668 }
1669 else if (classname != "" && food_stage)
1670 {
1671 return FoodStage.GetToxicity(null, food_stage, classname);
1672 }
1673 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1674 return GetGame().ConfigGetFloat( class_path + " toxicity" );
1675 }
1676
1677 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1678 {
1679 Edible_Base food_item = Edible_Base.Cast(item);
1680 if (food_item && food_item.GetFoodStage())
1681 {
1682 return FoodStage.GetAgents(food_item.GetFoodStage());
1683 }
1684 else if (classname != "" && food_stage)
1685 {
1686 return FoodStage.GetAgents(null, food_stage, classname);
1687 }
1688 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1689 return GetGame().ConfigGetInt( class_path + " agents" );
1690 }
1691
1692 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1693 {
1694 Edible_Base food_item = Edible_Base.Cast(item);
1695 if (food_item && food_item.GetFoodStage())
1696 {
1697 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1698 }
1699 else if (classname != "" && food_stage)
1700 {
1701 return FoodStage.GetDigestibility(null, food_stage, classname);
1702 }
1703 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1704 return GetGame().ConfigGetInt( class_path + " digestibility" );
1705 }
1706
1707 static float GetAgentsPerDigest(ItemBase item, string className = "", int foodStage = 0)
1708 {
1709 Edible_Base foodItem = Edible_Base.Cast(item);
1710 if (foodItem && foodItem.GetFoodStage())
1711 {
1712 return FoodStage.GetAgentsPerDigest(foodItem.GetFoodStage());
1713 }
1714 else if (className != "" && foodStage)
1715 {
1716 return FoodStage.GetAgentsPerDigest(null, foodStage, className);
1717 }
1718 string classPath = string.Format("cfgVehicles %1 Nutrition", className);
1719 return GetGame().ConfigGetInt(classPath + " agentsPerDigest");
1720 }
1721
1722 static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname = "", int food_stage = 0)
1723 {
1724 NutritionalProfile profile = new NutritionalProfile();
1725 profile.m_Energy = GetFoodEnergy(item, classname, food_stage);
1726 profile.m_WaterContent = GetFoodWater(item, classname, food_stage);
1727 profile.m_NutritionalIndex = GetFoodNutritionalIndex(item, classname, food_stage);
1728 profile.m_FullnessIndex = GetFoodTotalVolume(item, classname, food_stage);
1729 profile.m_Toxicity = GetFoodToxicity(item, classname, food_stage);
1730 profile.m_Agents = GetFoodAgents(item, classname, food_stage);
1731 profile.m_Digestibility = GetFoodDigestibility(item, classname, food_stage);
1732 profile.m_AgentsPerDigest = GetAgentsPerDigest(item, classname, food_stage);
1733
1734 return profile;
1735 }
1736
1737 //================================================================
1738 // FOOD STAGING
1739 //================================================================
1741 {
1742 return GetFoodStage().GetFoodStageType();
1743 }
1744
1745 //food stage states
1746 bool IsFoodRaw()
1747 {
1748 if ( GetFoodStage() )
1749 {
1750 return GetFoodStage().IsFoodRaw();
1751 }
1752
1753 return false;
1754 }
1755
1756 bool IsFoodBaked()
1757 {
1758 if ( GetFoodStage() )
1759 {
1760 return GetFoodStage().IsFoodBaked();
1761 }
1762
1763 return false;
1764 }
1765
1766 bool IsFoodBoiled()
1767 {
1768 if ( GetFoodStage() )
1769 {
1770 return GetFoodStage().IsFoodBoiled();
1771 }
1772
1773 return false;
1774 }
1775
1776 bool IsFoodDried()
1777 {
1778 if ( GetFoodStage() )
1779 {
1780 return GetFoodStage().IsFoodDried();
1781 }
1782
1783 return false;
1784 }
1785
1786 bool IsFoodBurned()
1787 {
1788 if ( GetFoodStage() )
1789 {
1790 return GetFoodStage().IsFoodBurned();
1791 }
1792
1793 return false;
1794 }
1795
1796 bool IsFoodRotten()
1797 {
1798 if ( GetFoodStage() )
1799 {
1800 return GetFoodStage().IsFoodRotten();
1801 }
1802
1803 return false;
1804 }
1805
1806 //food stage change
1807 void ChangeFoodStage( FoodStageType new_food_stage_type )
1808 {
1809 GetFoodStage().ChangeFoodStage( new_food_stage_type );
1810 }
1811
1813 {
1814 return GetFoodStage().GetNextFoodStageType( cooking_method );
1815 }
1816
1817 string GetFoodStageName( FoodStageType food_stage_type )
1818 {
1819 return GetFoodStage().GetFoodStageName( food_stage_type );
1820 }
1821
1822 bool CanChangeToNewStage( CookingMethodType cooking_method )
1823 {
1824 return GetFoodStage().CanChangeToNewStage( cooking_method );
1825 }
1826
1827 //Use this to receive food stage from another Edible_Base
1828 void TransferFoodStage( notnull Edible_Base source )
1829 {
1830 if ( !source.GetFoodStage())
1831 return;
1832 m_LastDecayStage = source.GetLastDecayStage();
1833 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1834 m_DecayTimer = source.GetDecayTimer();
1835 m_DecayDelta = source.GetDecayDelta();
1836 }
1837
1839 void OnFoodStageChange(FoodStageType stageOld, FoodStageType stageNew)
1840 {
1841 HandleFoodStageChangeAgents(stageOld,stageNew);
1842 UpdateVisualsEx(); //performed on server only
1843 }
1844
1847 {
1848 switch (stageNew)
1849 {
1850 case FoodStageType.BAKED:
1851 case FoodStageType.BOILED:
1852 case FoodStageType.DRIED:
1853 RemoveAllAgentsExcept(eAgents.BRAIN|eAgents.HEAVYMETAL);
1854 break;
1855
1856 case FoodStageType.BURNED:
1857 RemoveAllAgentsExcept(eAgents.BRAIN|eAgents.HEAVYMETAL);
1858 break;
1859 }
1860 }
1861
1862 //================================================================
1863 // COOKING
1864 //================================================================
1865 //cooking time
1866 float GetCookingTime()
1867 {
1868 return GetFoodStage().GetCookingTime();
1869 }
1870
1871 void SetCookingTime( float time )
1872 {
1873 GetFoodStage().SetCookingTime( time );
1874
1875 //synchronize when calling on server
1876 Synchronize();
1877 }
1878
1879 void ResetCookingTime()
1880 {
1881 if (GetFoodStage())
1882 {
1883 GetFoodStage().SetCookingTime(0);
1884 Synchronize();
1885 }
1886 }
1887
1888 //replace edible with new item (opening cans)
1889 void ReplaceEdibleWithNew( string typeName )
1890 {
1891 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1892 if (player)
1893 {
1894 ReplaceEdibleWithNewLambda lambda = new ReplaceEdibleWithNewLambda(this, typeName, player);
1895 player.ServerReplaceItemInHandsWithNew(lambda);
1896 }
1897 else
1898 Error("ReplaceEdibleWithNew - cannot use edible without player");
1899 }
1900
1902 {
1904 }
1905
1906 override void SetActions()
1907 {
1908 super.SetActions();
1909
1912 }
1913
1914 protected void SoundCookingStart(string sound_name)
1915 {
1916 #ifndef SERVER
1917 if (m_SoundPlaying != sound_name)
1918 {
1920
1921 m_SoundEffectCooking = SEffectManager.PlaySound(sound_name, GetPosition(), 0, 0, true);
1922 m_SoundPlaying = sound_name;
1923 }
1924 #endif
1925 }
1926
1927 protected void SoundCookingStop()
1928 {
1929 #ifndef SERVER
1931 {
1932 m_SoundEffectCooking.Stop();
1933 m_SoundEffectCooking = null;
1934 m_SoundPlaying = "";
1935 }
1936 #endif
1937 }
1938
1939 override bool CanDecay()
1940 {
1941 return false;
1942 }
1943
1944 override bool CanProcessDecay()
1945 {
1946 return !GetIsFrozen() && ( GetFoodStageType() != FoodStageType.ROTTEN );
1947 }
1948
1949 override void ProcessDecay( float delta, bool hasRootAsPlayer )
1950 {
1951 m_DecayDelta = 0.0;
1952
1953 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1954 m_DecayDelta += ( 1 + ( 1 - GetHealth01( "", "" ) ) );
1955 if ( hasRootAsPlayer )
1957
1958 /*Print( "-------------------------" );
1959 Print( this );
1960 Print( m_DecayTimer );
1961 Print( m_DecayDelta );
1962 Print( m_LastDecayStage );*/
1963
1964 if ( IsFruit() || IsMushroom() )
1965 {
1966 // fruit, vegetables and mushrooms
1968 {
1969 switch ( GetFoodStageType() )
1970 {
1971 case FoodStageType.RAW:
1974 break;
1975
1976 case FoodStageType.BOILED:
1979 break;
1980
1981 case FoodStageType.BAKED:
1984 break;
1985
1986 case FoodStageType.DRIED:
1987 case FoodStageType.BURNED:
1988 case FoodStageType.ROTTEN:
1989 default:
1990 m_DecayTimer = -1;
1992 return;
1993 }
1994
1995 //m_DecayTimer = m_DecayTimer / 1000.0;
1996 }
1997
1998 m_DecayTimer -= ( delta * m_DecayDelta );
1999
2000 if ( m_DecayTimer <= 0 )
2001 {
2002 if ( m_LastDecayStage != FoodStageType.NONE )
2003 {
2004 // switch to decayed stage
2005 if ( ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
2006 {
2008 }
2009 if ( m_LastDecayStage == FoodStageType.RAW )
2010 {
2011 int rng = Math.RandomIntInclusive( 0, 100 );
2013 {
2015 }
2016 else
2017 {
2018 if ( CanChangeToNewStage( FoodStageType.DRIED ) )
2019 {
2021 }
2022 else
2023 {
2025 }
2026 }
2027 }
2028 }
2029 }
2030
2031 }
2032 else if ( IsMeat() )
2033 {
2034 // meat
2036 {
2037 switch ( GetFoodStageType() )
2038 {
2039 case FoodStageType.RAW:
2042 break;
2043
2044 case FoodStageType.BOILED:
2047 break;
2048
2049 case FoodStageType.BAKED:
2052 break;
2053
2054 case FoodStageType.DRIED:
2057 break;
2058
2059 case FoodStageType.BURNED:
2060 case FoodStageType.ROTTEN:
2061 default:
2062 m_DecayTimer = -1;
2064 return;
2065 }
2066 }
2067
2068 m_DecayTimer -= ( delta * m_DecayDelta );
2069
2070 if ( m_DecayTimer <= 0 )
2071 {
2072 if ( m_LastDecayStage != FoodStageType.NONE )
2073 {
2074 // switch to decayed stage
2075 if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
2076 {
2078 }
2079 }
2080 }
2081 }
2082 else if ( IsCorpse() )
2083 {
2084 // corpse
2086 {
2087 switch ( GetFoodStageType() )
2088 {
2089 case FoodStageType.RAW:
2092 break;
2093
2094 case FoodStageType.BURNED:
2095 case FoodStageType.ROTTEN:
2096 default:
2097 m_DecayTimer = -1;
2099 return;
2100 }
2101 }
2102
2103 m_DecayTimer -= ( delta * m_DecayDelta );
2104
2105 if ( m_DecayTimer <= 0 )
2106 {
2107 if ( m_LastDecayStage != FoodStageType.NONE )
2108 {
2109 // switch to decayed stage
2110 if ( ( m_LastDecayStage == FoodStageType.DRIED ) || ( m_LastDecayStage == FoodStageType.RAW ) || ( m_LastDecayStage == FoodStageType.BOILED ) || ( m_LastDecayStage == FoodStageType.BAKED ) )
2111 {
2113 }
2114 }
2115 }
2116 }
2117 else
2118 {
2119 // opened cans
2120 m_DecayTimer -= ( delta * m_DecayDelta );
2121
2122 if ( ( m_DecayTimer <= 0 ) && ( m_LastDecayStage == FoodStageType.NONE ) )
2123 {
2126 //m_DecayTimer = m_DecayTimer / 1000.0;
2127 }
2128 else
2129 {
2130 if ( m_DecayTimer <= 0 )
2131 {
2132 InsertAgent(eAgents.FOOD_POISON, 1);
2133 m_DecayTimer = -1;
2134 }
2135 }
2136 }
2137 }
2138
2139 protected void UpdateVaporParticle()
2140 {
2141 if (GetGame().IsDedicatedServer())
2142 return;
2143
2144 if (m_VarTemperature >= GameConstants.STATE_HOT_LVL_TWO && !m_HotVaporParticle)
2145 {
2146 InventoryLocation invLoc = new InventoryLocation();
2147 GetInventory().GetCurrentInventoryLocation(invLoc);
2148 if (invLoc && (invLoc.GetType() == InventoryLocationType.GROUND || invLoc.GetType() == InventoryLocationType.HANDS || invLoc.GetType() == InventoryLocationType.ATTACHMENT))
2149 {
2150 ParticleManager ptcMgr = ParticleManager.GetInstance();
2151 if (ptcMgr)
2152 {
2153 m_HotVaporParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.ITEM_HOT_VAPOR, this);
2154 m_HotVaporParticle.SetParticleParam(EmitorParam.SIZE, 0.3);
2155 m_HotVaporParticle.SetParticleParam(EmitorParam.BIRTH_RATE, 10);
2156 m_HotVaporParticle.SetParticleAutoDestroyFlags(ParticleAutoDestroyFlags.ON_STOP);
2157 }
2158 }
2159 }
2160 else if (m_HotVaporParticle)
2161 {
2162 if (m_VarTemperature <= GameConstants.STATE_HOT_LVL_TWO)
2163 {
2164 m_HotVaporParticle.Stop();
2165 m_HotVaporParticle = null;
2166 return;
2167 }
2168
2169 InventoryLocation inventoryLoc = new InventoryLocation();
2170 GetInventory().GetCurrentInventoryLocation(inventoryLoc);
2171 if (invLoc && (invLoc.GetType() != InventoryLocationType.GROUND && invLoc.GetType() != InventoryLocationType.HANDS))
2172 {
2173 m_HotVaporParticle.Stop();
2174 m_HotVaporParticle = null;
2175 }
2176 }
2177 }
2178
2179 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
2180 {
2181 super.GetDebugActions(outputList);
2182
2183 if (GetFoodStage())
2184 {
2185 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_NUTRITIONS_DATA, "Food Nutritions Data", FadeColors.WHITE));
2186 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2187 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2188 }
2189 }
2190
2191 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2192 {
2193 super.OnAction(action_id, player, ctx);
2194
2195 if ( GetGame().IsServer() )
2196 {
2197 if ( action_id == EActions.FOOD_STAGE_PREV )
2198 {
2199 int food_stage_prev = GetFoodStageType() - 1;
2200 if (food_stage_prev <= 0)
2201 {
2202 food_stage_prev = FoodStageType.COUNT - 1;
2203 }
2204 ChangeFoodStage(food_stage_prev);
2205 return true;
2206 }
2207 else if ( action_id == EActions.FOOD_STAGE_NEXT )
2208 {
2209 int food_stage_next = GetFoodStageType() + 1;
2210 if (food_stage_next >= FoodStageType.COUNT )
2211 {
2212 food_stage_next = FoodStageType.RAW;
2213 }
2214 ChangeFoodStage(food_stage_next);
2215 return true;
2216 }
2217
2218 }
2219
2220 #ifdef DIAG_DEVELOPER
2221 if (action_id == EActions.FOOD_NUTRITIONS_DATA)
2222 {
2223 PrintNutritionsData();
2224 return true;
2225 }
2226 #endif
2227
2228 return false;
2229 }
2230
2231 override string GetDebugText()
2232 {
2233 string debug_output;
2234
2235 debug_output = super.GetDebugText();
2236
2237 debug_output+="m_CookedByMethod:"+m_CookedByMethod+"\n";
2238 debug_output+="m_MakeCookingSounds:"+m_MakeCookingSounds+"\n";
2239
2240 return debug_output;
2241 }
2242
2243 //================================================================
2244 // GENERAL GETTERS
2245 //================================================================
2246
2247 override float GetBaitEffectivity()
2248 {
2249 float ret = super.GetBaitEffectivity();
2250
2251 if (IsFoodRotten())
2252 {
2253 ret *= 0.5;
2254 }
2255
2256 return ret;
2257 }
2258
2259 float GetDecayTimer()
2260 {
2261 return m_DecayTimer;
2262 }
2263
2264 float GetDecayDelta()
2265 {
2266 return m_DecayDelta;
2267 }
2268
2270 {
2271 return m_LastDecayStage;
2272 }
2273
2274 #ifdef DIAG_DEVELOPER
2275 private void PrintNutritionsData()
2276 {
2277 string nutritionsData = "";
2278
2279 FoodStage stage = GetFoodStage();
2280 FoodStageType stageType = stage.GetFoodStageType();
2281
2282 NutritionalProfile profile = GetNutritionalProfile(this, ClassName(), stageType);
2283 if (profile)
2284 {
2285 nutritionsData = string.Format("Item: %1\n\n", this);
2286 nutritionsData += string.Format("Stage name: %1\n", GetFoodStageName(stageType));
2287 nutritionsData += string.Format("Energy: %1\n", profile.m_Energy);
2288 nutritionsData += string.Format("Water content: %1\n", profile.m_WaterContent);
2289 nutritionsData += string.Format("Nutritional index: %1\n", profile.m_NutritionalIndex);
2290 nutritionsData += string.Format("Fullness index: %1\n", profile.m_FullnessIndex);
2291 nutritionsData += string.Format("Toxicity (obsolete): %1\n", profile.m_Toxicity);
2292 nutritionsData += string.Format("Digestibility: %1\n", profile.m_Digestibility);
2293
2294 if (profile.IsLiquid())
2295 nutritionsData += string.Format("Liquid type: %1\n", profile.m_LiquidClassname);
2296
2297 nutritionsData += string.Format("Agents: %1\n", profile.m_Agents);
2298 nutritionsData += string.Format("Agents per consume: %1\n", profile.m_AgentsPerDigest);
2299 }
2300
2301 nutritionsData += "-----\n";
2302
2303 Debug.Log(nutritionsData);
2304 }
2305 #endif
2306
2308 //DEPRECATED
2310 void UpdateVisuals()
2311 {
2313 }
2314}
2315
2317{
2318 void ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player) { }
2319};
Param4< int, int, string, int > TSelectableActionInfoWithColor
Определения EntityAI.c:97
class LogManager EntityAI
eBleedingSourceType GetType()
Определения BleedingSource.c:63
AttachActionData ActionData ActionAttach()
Определения ActionAttach.c:9
void ActionDetach()
Определения ActionDetach.c:10
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
CookingMethodType
Определения Cooking.c:2
DamageType
exposed from C++ (do not change)
Определения DamageSystem.c:11
EActions
Определения EActions.c:2
eAgents
Определения EAgents.c:3
EConsumptionPenaltyContext
Определения EConsumptionPenaltyContext.c:2
void ReplaceEdibleWithNew(string typeName)
Определения Edible_Base.c:1787
ref FoodStage m_FoodStage
Определения Edible_Base.c:1124
bool IsFoodRotten()
Определения Edible_Base.c:1694
static float GetFoodWater(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1529
override bool CanBeCooked()
Определения Edible_Base.c:1236
bool IsFoodBaked()
Определения Edible_Base.c:1654
override string GetDebugText()
Определения Edible_Base.c:2129
override void AfterStoreLoad()
Определения Edible_Base.c:1460
string m_SoundPlaying
Определения Edible_Base.c:1123
void Edible_Base()
Определения Edible_Base.c:1132
void OnFoodStageChange(FoodStageType stageOld, FoodStageType stageNew)
called on server
Определения Edible_Base.c:1737
float m_DecayDelta
Определения Edible_Base.c:1126
void Synchronize()
Определения Edible_Base.c:1294
override void OnVariablesSynchronized()
Определения Edible_Base.c:1299
const string SOUND_BURNING_DONE
Определения Edible_Base.c:1118
bool CanChangeToNewStage(CookingMethodType cooking_method)
Определения Edible_Base.c:1720
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Определения Edible_Base.c:2089
void RemoveAudio()
Определения Edible_Base.c:1406
override bool CanItemOverheat()
Определения Edible_Base.c:1286
float GetDecayDelta()
Определения Edible_Base.c:2162
override float GetBaitEffectivity()
Определения Edible_Base.c:2145
override FoodStage GetFoodStage()
Определения Edible_Base.c:1468
override void SetActions()
Определения Edible_Base.c:1804
bool m_MakeCookingSounds
Определения Edible_Base.c:1120
override float GetTemperatureFreezeTime()
Определения Edible_Base.c:1246
void SoundCookingStop()
Определения Edible_Base.c:1825
const string DIRECT_COOKING_SLOT_NAME
Определения Edible_Base.c:1110
FoodStageType GetNextFoodStageType(CookingMethodType cooking_method)
Определения Edible_Base.c:1710
void ChangeFoodStage(FoodStageType new_food_stage_type)
Определения Edible_Base.c:1705
void OnConsume(float amount, PlayerBase consumer)
Определения Edible_Base.c:1210
static float GetFoodNutritionalIndex(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1544
SoundOnVehicle m_SoundCooking
Определения Edible_Base.c:1121
static float GetFoodToxicity(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1560
override bool CanDecay()
Определения Edible_Base.c:1837
void UpdateVisualsEx(bool forced=false)
Определения Edible_Base.c:1196
const string SOUND_BAKING_DONE
Определения Edible_Base.c:1113
static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1620
int FilterAgents(int agentsIn)
Filter agents from the item (override on higher implementations)
Определения Edible_Base.c:1219
override void EEDelete(EntityAI parent)
Определения Edible_Base.c:1155
FoodStageType m_LastDecayStage
Определения Edible_Base.c:1127
float GetCookingTime()
Определения Edible_Base.c:1764
override bool CanBeCookedOnStick()
Определения Edible_Base.c:1241
override bool IsCorpse()
Определения Edible_Base.c:1479
void UpdateVisuals()
Определения Edible_Base.c:2208
float GetDecayTimer()
Определения Edible_Base.c:2157
FoodStageType GetLastDecayStage()
Определения Edible_Base.c:2167
string GetFoodStageName(FoodStageType food_stage_type)
Определения Edible_Base.c:1715
override float GetTemperatureThawTime()
Определения Edible_Base.c:1266
void UpdateVaporParticle()
Определения Edible_Base.c:2037
static float GetFoodDigestibility(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1590
void TransferFoodStage(notnull Edible_Base source)
Определения Edible_Base.c:1726
override void ProcessDecay(float delta, bool hasRootAsPlayer)
Определения Edible_Base.c:1847
const string SOUND_DRYING_START
Определения Edible_Base.c:1116
void SetCookingTime(float time)
Определения Edible_Base.c:1769
void SoundCookingStart(string sound_name)
Определения Edible_Base.c:1812
override bool IsMeat()
Определения Edible_Base.c:1474
const string SOUND_BAKING_START
Определения Edible_Base.c:1112
static float GetFoodTotalVolume(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1498
const string SOUND_DRYING_DONE
Определения Edible_Base.c:1117
void HandleFoodStageChangeAgents(FoodStageType stageOld, FoodStageType stageNew)
removes select agents on foodstage transitions
Определения Edible_Base.c:1744
void ResetCookingTime()
Определения Edible_Base.c:1777
override bool IsFruit()
Определения Edible_Base.c:1484
Edible_Base ItemBase ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player)
Определения Edible_Base.c:1109
bool Consume(float amount, PlayerBase consumer)
Определения Edible_Base.c:1202
EffectSound m_SoundEffectCooking
DEPRECATED.
Определения Edible_Base.c:1122
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения Edible_Base.c:1429
FoodStageType GetFoodStageType()
Определения Edible_Base.c:1638
override bool CanProcessDecay()
Определения Edible_Base.c:1842
ParticleSource m_HotVaporParticle
Определения Edible_Base.c:1128
void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod=CookingMethodType.NONE)
Определения Edible_Base.c:1322
static int GetFoodAgents(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1575
override bool IsMushroom()
Определения Edible_Base.c:1489
static float GetFoodEnergy(ItemBase item, string classname="", int food_stage=0)
Определения Edible_Base.c:1514
static float GetAgentsPerDigest(ItemBase item, string className="", int foodStage=0)
Определения Edible_Base.c:1605
void RefreshAudio()
Определения Edible_Base.c:1330
const string SOUND_BOILING_DONE
Определения Edible_Base.c:1115
int GetConsumptionPenaltyContext()
Определения Edible_Base.c:1799
const string SOUND_BOILING_START
Определения Edible_Base.c:1114
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Определения Edible_Base.c:2077
CookingMethodType m_CookedByMethod
Определения Edible_Base.c:1130
bool IsFoodDried()
Определения Edible_Base.c:1674
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Определения Edible_Base.c:1165
override void OnStoreSave(ParamsWriteContext ctx)
Определения Edible_Base.c:1415
bool IsFoodRaw()
Определения Edible_Base.c:1644
bool IsFoodBurned()
Определения Edible_Base.c:1684
override void EEInit()
Определения Edible_Base.c:1148
bool IsFoodBoiled()
Определения Edible_Base.c:1664
float m_DecayTimer
Определения Edible_Base.c:1125
override bool CanHaveTemperature()
Определения FireplaceBase.c:557
FoodStageType
Определения FoodStage.c:2
InventoryLocationType
types of Inventory Location
Определения InventoryLocation.c:4
override void InsertAgent(int agent, float count=1)
Определения ItemBase.c:8653
override void RemoveAllAgentsExcept(int agent_to_keep)
Определения ItemBase.c:8648
bool AddQuantity(float value, bool destroy_config=true, bool destroy_forced=false)
add item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity re...
Определения ItemBase.c:8060
bool HasFoodStage()
Определения ItemBase.c:7324
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Определения ParticleManager.c:88
ParticleAutoDestroyFlags
Flags to pass to ParticleSource.SetParticleAutoDestroyFlags.
Определения ParticleSource.c:3
proto native float ConfigGetFloat(string path)
Get float value from config on path.
proto native int ConfigGetInt(string path)
Get int value from config on path.
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Определения Debug.c:122
Определения Debug.c:2
override FoodStage GetFoodStage()
Определения Edible_Base.c:361
Определения Edible_Base.c:2
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения Building.c:6
Определения constants.c:659
proto native int GetType()
returns type of InventoryLocation
InventoryLocation.
Определения InventoryLocation.c:29
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
Определения InventorySlots.c:6
override void EEInit()
Определения BarbedWire.c:41
Определения InventoryItem.c:731
Определения EnMath.c:7
float m_Digestibility
Определения NutritionalProfile.c:11
bool IsLiquid()
Определения NutritionalProfile.c:47
float m_WaterContent
Определения NutritionalProfile.c:4
string m_LiquidClassname
Определения NutritionalProfile.c:10
float m_FullnessIndex
Определения NutritionalProfile.c:6
float m_Toxicity
Определения NutritionalProfile.c:7
float m_Energy
Определения NutritionalProfile.c:3
int m_Agents
Определения NutritionalProfile.c:9
float m_AgentsPerDigest
Определения NutritionalProfile.c:12
float m_NutritionalIndex
Определения NutritionalProfile.c:5
static const int ITEM_HOT_VAPOR
Определения ParticleList.c:70
Определения ParticleList.c:12
Entity which has the particle instance as an ObjectComponent.
Определения ParticleSource.c:124
Определения PlayerBaseClient.c:2
static const float CONSUMPTION_DAMAGE_PER_BITE
Определения PlayerConstants.c:145
static const float CONSUMPTION_DAMAGE_TEMP_THRESHOLD
Определения PlayerConstants.c:146
Определения PlayerConstants.c:2
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Определения EffectManager.c:169
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
const float DECAY_FOOD_BAKED_FRVG
Определения constants.c:1038
const float DECAY_FOOD_CAN_OPEN
Определения constants.c:1040
const float DECAY_FOOD_RAW_FRVG
Определения constants.c:1034
const int DECAY_TIMER_RANDOM_PERCENTAGE
Определения constants.c:1042
const int DECAY_FOOD_FRVG_DRIED_CHANCE
Определения constants.c:1041
const float DECAY_FOOD_RAW_MEAT
Определения constants.c:1032
const float DECAY_FOOD_BAKED_MEAT
Определения constants.c:1037
const float DECAY_FOOD_BOILED_MEAT
Определения constants.c:1035
const float DECAY_FOOD_BOILED_FRVG
Определения constants.c:1036
const float DECAY_FOOD_DRIED_MEAT
Определения constants.c:1039
const float DECAY_FOOD_RAW_CORPSE
Определения constants.c:1033
const float DECAY_RATE_ON_PLAYER
Определения constants.c:1043
static const float TEMPERATURE_THAW_TIME_COEF_BURNED
Определения constants.c:935
static const float TEMPERATURE_FREEZE_TIME_COEF_BURNED
Определения constants.c:934
static const float TEMPERATURE_THAW_TIME_COEF_DRIED
Определения constants.c:936
static const float TEMPERATURE_FREEZE_TIME_COEF_DRIED
Определения constants.c:933
const int STATE_HOT_LVL_TWO
Определения constants.c:884
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:126
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Определения EnMath.c:54
EmitorParam
Определения EnVisual.c:114
const int SAT_DEBUG_ACTION
Определения constants.c:452
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
bool Contains(string sample)
Returns true if sample is substring of string.
Определения EnString.c:286
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.