Beispiel #1
0
 public static void OnNPCLoaded(NPC.NPCBase npc, JSONNode node)
 {
     if (node.TryGetAs <JSONNode>(GameLoader.SETTLER_INV, out var invNode))
     {
         npc.GetTempValues(true).Set(GameLoader.SETTLER_INV, new SettlerInventory(invNode));
     }
 }
Beispiel #2
0
 public static void OnNPCHit(NPC.NPCBase npc, Pipliz.Box <float> box)
 {
     if (npc != null && npc.Job != null && npc.Job.GetType() == typeof(Jobs.Knight))
     {
         box.Set(box.item1 - (box.item1 * .65f));
     }
 }
        public static bool GetBestWeapon(NPC.NPCBase npc, int limit)
        {
            var hasItem = false;

            try
            {
                if (npc != null)
                {
                    var inv   = ColonistInventory.Get(npc);
                    var stock = npc.Colony.Stockpile;

                    hasItem = !inv.Weapon.IsEmpty();
                    IWeapon bestWeapon = null;

                    if (hasItem)
                    {
                        bestWeapon = WeaponFactory.WeaponLookup[inv.Weapon.Id];
                    }

                    foreach (var wep in WeaponFactory.WeaponLookup.Values.Where(w => w as IPlayerMagicItem == null && w is WeaponMetadata weaponMetadata && weaponMetadata.ItemType != null).Cast <WeaponMetadata>())
                    {
                        if (stock.Contains(wep.ItemType.ItemIndex) && bestWeapon == null ||
                            stock.Contains(wep.ItemType.ItemIndex) && bestWeapon != null &&
                            bestWeapon.Damage.TotalDamage() < wep.Damage.TotalDamage() &&
                            stock.AmountContained(ItemId.GetItemId(bestWeapon.name)) > limit)
                        {
                            bestWeapon = wep;
                        }
                    }

                    if (bestWeapon != null)
                    {
                        var wepId = ItemId.GetItemId(bestWeapon.name);
                        if (hasItem && inv.Weapon.Id != wepId || !hasItem)
                        {
                            hasItem = true;
                            stock.TryRemove(wepId);

                            if (!inv.Weapon.IsEmpty())
                            {
                                stock.Add(inv.Weapon.Id);
                            }

                            inv.Weapon = new ItemState
                            {
                                Id         = wepId,
                                Durability = bestWeapon.WepDurability
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                APILogger.LogError(ex);
            }

            return(hasItem);
        }
Beispiel #4
0
 public void OnAssignedNPC(NPCBase npc)
 {
     _usedNPC     = npc;
     _tmpVals     = npc.GetTempValues(true);
     _colony      = npc.Colony;
     _inv         = SettlerInventory.GetSettlerInventory(npc);
     _playerState = PlayerState.GetPlayerState(_colony.Owner);
     _stock       = Stockpile.GetStockPile(_colony.Owner);
 }
Beispiel #5
0
        public virtual void OnRemove()
        {
            _isValid = false;

            if (_usedNPC != null)
            {
                _usedNPC.ClearJob();
                _usedNPC = null;
            }
        }
        public static void Heal(this NPC.NPCBase nPC, float heal)
        {
            nPC.health += heal;

            if (nPC.health > NPC.NPCBase.MaxHealth)
            {
                nPC.health = NPC.NPCBase.MaxHealth;
            }

            nPC.Update();
        }
        public static GuardBaseJob.GuardSettings GetWeapon(NPC.NPCBase npc)
        {
            GuardBaseJob.GuardSettings weapon = null;
            var inv = SettlerInventory.GetSettlerInventory(npc);

            foreach (var w in Items.ItemFactory.WeaponGuardSettings)
            {
                if (npc.Inventory.Contains(w.recruitmentItem) || inv.Weapon.Id == w.recruitmentItem.Type)
                {
                    weapon = w;
                    break;
                }
            }

            return(weapon);
        }
Beispiel #8
0
 public static void OnNPCSaved(NPC.NPCBase npc, JSONNode node)
 {
     node.SetAs(GameLoader.SETTLER_INV, SettlerInventory.GetSettlerInventory(npc).ToJsonNode());
 }
Beispiel #9
0
 public static void OnNPCDied(NPC.NPCBase npc)
 {
     SettlerInventory.GetSettlerInventory(npc);
     UpdateFoodUse(npc.Colony.Owner);
 }
Beispiel #10
0
 public void OnRemovedNPC()
 {
     _usedNPC = null;
     JobTracker.Add(this);
 }