private static void UpdateMagicItemms(ColonyState state) { try { if (state.HealingUpdateTime < Time.SecondsSinceStartDouble) { var colony = state.ColonyRef; foreach (var follower in colony.Followers) { var inv = ColonistInventory.Get(follower); if (inv.HealingItemUpdateTime < Time.SecondsSinceStartDouble) { var hasBandages = colony.Stockpile.Contains(TreatedBandage.Item.ItemIndex) || colony.Stockpile.Contains(Bandage.Item.ItemIndex); if (hasBandages && follower.health < follower.Colony.NPCHealthMax && !HealingOverTimeNPC.NPCIsBeingHealed(follower)) { var healing = false; if (follower.Colony.NPCHealthMax - follower.health > TreatedBandage.INITIALHEAL) { colony.Stockpile.TryRemove(TreatedBandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, TreatedBandage.INITIALHEAL, TreatedBandage.TOTALHOT, 5, TreatedBandage.Item.ItemIndex); } if (!healing) { colony.Stockpile.TryRemove(Bandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, Bandage.INITIALHEAL, Bandage.TOTALHOT, 5, Bandage.Item.ItemIndex); } } inv.HealingItemUpdateTime = Time.SecondsSinceStartDouble + Random.Next(3, 5); } } state.HealingUpdateTime = Time.SecondsSinceStartDouble + 5; } } catch (Exception ex) { SettlersLogger.LogError(ex); } }
public static void Click(Players.Player player, Box <PlayerClickedData> boxedData) { var healed = false; if (!_coolDown.ContainsKey(player)) { _coolDown.Add(player, 0); } if (boxedData.item1.clickType == PlayerClickedData.ClickType.Right && boxedData.item1.typeSelected == Item.ItemIndex) { if (Time.MillisecondsSinceStart > _coolDown[player]) { var healing = new HealingOverTimePC(player, INITIALHEAL, TOTALHOT, 5); healed = true; } } else if (boxedData.item1.clickType == PlayerClickedData.ClickType.Left && boxedData.item1.typeSelected == Item.ItemIndex && boxedData.item1.rayCastHit.rayHitType == RayHitType.NPC) { if (NPCTracker.TryGetNPC(boxedData.item1.rayCastHit.hitNPCID, out var npc)) { if (Time.MillisecondsSinceStart > _coolDown[player]) { var heal = new HealingOverTimeNPC(npc, INITIALHEAL, TOTALHOT, 5, Item.ItemIndex); healed = true; } } } if (healed) { _coolDown[player] = Time.MillisecondsSinceStart + COOLDOWN; boxedData.item1.consumedType = PlayerClickedData.ConsumedType.UsedByMod; ServerManager.SendAudio(player.Position, GameLoader.NAMESPACE + ".Bandage"); if (Inventory.TryGetInventory(player, out var inv)) { inv.TryRemove(Item.ItemIndex); } } }
public static void Click(Players.Player player, PlayerClickedData playerClickData) { var healed = false; if (!_coolDown.ContainsKey(player)) { _coolDown.Add(player, 0); } if (playerClickData.ClickType == PlayerClickedData.EClickType.Right && playerClickData.TypeSelected == Item.ItemIndex) { if (Time.MillisecondsSinceStart > _coolDown[player]) { var healing = new HealingOverTimePC(player, INITIALHEAL, TOTALHOT, 5); healed = true; } } else if (playerClickData.ClickType == PlayerClickedData.EClickType.Left && playerClickData.TypeSelected == Item.ItemIndex && playerClickData.HitType == PlayerClickedData.EHitType.NPC) { if (NPCTracker.TryGetNPC(playerClickData.GetNPCHit().NPCID, out var npc)) { if (Time.MillisecondsSinceStart > _coolDown[player]) { var heal = new HealingOverTimeNPC(npc, INITIALHEAL, TOTALHOT, 5, Item.ItemIndex); healed = true; } } } if (healed) { _coolDown[player] = Time.MillisecondsSinceStart + COOLDOWN; playerClickData.ConsumedType = PlayerClickedData.EConsumedType.UsedByMod; AudioManager.SendAudio(player.Position, GameLoader.NAMESPACE + ".Bandage"); player.Inventory.TryRemove(Item.ItemIndex); } }
public static void OnUpdate() { if (ServerManager.ColonyTracker != null) { foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values) { if (_magicUpdateTime < Time.SecondsSinceStartDouble) { foreach (var follower in colony.Followers) { var inv = SettlerInventory.GetSettlerInventory(follower); if (inv.MagicItemUpdateTime < Time.SecondsSinceStartDouble) { foreach (var item in inv.Armor) { if (item.Value.Id != 0 && ArmorFactory.ArmorLookup.TryGetValue(item.Value.Id, out var armor)) { armor.Update(); if (armor.HPTickRegen != 0) { follower.Heal(armor.HPTickRegen); } } } if (Items.Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var wep)) { wep.Update(); if (wep.HPTickRegen != 0) { follower.Heal(wep.HPTickRegen); } } var hasBandages = colony.Stockpile.Contains(TreatedBandage.Item.ItemIndex) || colony.Stockpile.Contains(Bandage.Item.ItemIndex); if (hasBandages && follower.health < follower.Colony.NPCHealthMax && !HealingOverTimeNPC.NPCIsBeingHealed(follower)) { var healing = false; if (follower.Colony.NPCHealthMax - follower.health > TreatedBandage.INITIALHEAL) { colony.Stockpile.TryRemove(TreatedBandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, TreatedBandage.INITIALHEAL, TreatedBandage.TOTALHOT, 5, TreatedBandage.Item.ItemIndex); } if (!healing) { colony.Stockpile.TryRemove(Bandage.Item.ItemIndex); healing = true; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, Bandage.INITIALHEAL, Bandage.TOTALHOT, 5, Bandage.Item.ItemIndex); } } inv.MagicItemUpdateTime += 5000; } } } if (_updateTime < Time.SecondsSinceStartDouble && colony.OwnerIsOnline()) { NPCBase lastNPC = null; foreach (var follower in colony.Followers) { if (TimeCycle.IsDay) { if (lastNPC == null || UnityEngine.Vector3.Distance(lastNPC.Position.Vector, follower.Position.Vector) > 15 && Random.NextBool()) { lastNPC = follower; AudioManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".TalkingAudio"); } } } } var cs = ColonyState.GetColonyState(colony); if (cs.SettlersEnabled) { if (EvaluateSettlers(cs) || EvaluateLaborers(cs) || EvaluateBeds(cs)) { colony.SendCommonData(); } } UpdateFoodUse(cs); } } if (_magicUpdateTime < Time.SecondsSinceStartDouble) { _magicUpdateTime = Time.SecondsSinceStartDouble + 1; } if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay) { _updateTime = Time.SecondsSinceStartDouble + _UPDATE_TIME; } }
public static void OnUpdate() { Players.PlayerDatabase.ForeachValue(p => { var stockpile = Stockpile.GetStockPile(p); var colony = Colony.Get(p); var hasBandages = stockpile.Contains(TreatedBandage.Item.ItemIndex) || stockpile.Contains(Bandage.Item.ItemIndex); if (hasBandages) { foreach (var follower in colony.Followers) { if (follower.health < NPCBase.MaxHealth && !HealingOverTimeNPC.NPCIsBeingHealed(follower)) { var healing = false; if (NPCBase.MaxHealth - follower.health > TreatedBandage.INITIALHEAL) { stockpile.TryRemove(TreatedBandage.Item.ItemIndex); healing = true; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, TreatedBandage.INITIALHEAL, TreatedBandage.TOTALHOT, 5, TreatedBandage.Item.ItemIndex); } if (!healing) { stockpile.TryRemove(Bandage.Item.ItemIndex); healing = true; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".Bandage"); var heal = new HealingOverTimeNPC(follower, Bandage.INITIALHEAL, Bandage.TOTALHOT, 5, Bandage.Item.ItemIndex); } } } } if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay && p.IsConnected) { NPCBase lastNPC = null; foreach (var follower in colony.Followers) { if (lastNPC == null || Vector3.Distance(lastNPC.Position.Vector, follower.Position.Vector) > 15 && Random.NextBool()) { lastNPC = follower; ServerManager.SendAudio(follower.Position.Vector, GameLoader.NAMESPACE + ".TalkingAudio"); } } } var ps = PlayerState.GetPlayerState(p); if (ps.SettlersEnabled) { if (EvaluateSettlers(p) || EvaluateLaborers(p) || EvaluateBeds(p)) { colony.SendUpdate(); } } UpdateFoodUse(p); }); if (_updateTime < Time.SecondsSinceStartDouble && TimeCycle.IsDay) { _updateTime = Time.SecondsSinceStartDouble + 10; } }