Beispiel #1
0
        private static void NPCLeaving(NPCBase npc)
        {
            if (Random.NextFloat() > .49f)
            {
                float cost = ColonistManager.PenalizeFood(npc.Colony, 0.05f);

                PandaChat.Send(npc.Colony, _localizationHelper, "TakenFood", ChatColor.red);
            }
            else
            {
                var numberOfItems = Random.Next(1, 10);

                for (var i = 0; i < numberOfItems; i++)
                {
                    var randItem = Random.Next(npc.Colony.Stockpile.ItemCount);
                    var item     = npc.Colony.Stockpile.GetByIndex(randItem);

                    if (item.Type != ColonyBuiltIn.ItemTypes.AIR.Id && item.Amount != 0)
                    {
                        var leaveTax = Pipliz.Math.RoundToInt(item.Amount * .10);
                        npc.Colony.Stockpile.TryRemove(item.Type, leaveTax);

                        PandaChat.Send(npc.Colony, _localizationHelper, "LeavingTakingItems", ChatColor.red, leaveTax.ToString(), ItemId.GetItemId(item.Type).Name);
                    }
                }

                PandaChat.Send(npc.Colony, _localizationHelper, "LeavingNumberOfItems", ChatColor.red, numberOfItems.ToString());
            }

            npc.health = 0;
            npc.OnDeath();
        }
 public void ResearchComplete(object sender, ResearchCompleteEventArgs e)
 {
     ColonistManager.ApplyJobCooldownsToNPCs(e.Manager.Colony);
 }
        private static void CantSpawnBoss(ColonyState cs)
        {
            cs.FaiedBossSpawns++;

            if (cs.FaiedBossSpawns > 10)
            {
                PandaChat.SendThrottle(cs, _localizationHelper, "NoBanner", ChatColor.red, ColonistManager.PenalizeFood(cs.ColonyRef, 0.15f) * 100 + "%");
            }

            cs.ColonyRef.OnZombieSpawn(false);
        }
        public static void OnMonsterHit(IMonster monster, ModLoader.OnHitData d)
        {
            var cs          = ColonyState.GetColonyState(monster.OriginalGoal);
            var pandaArmor  = monster as IPandaArmor;
            var pamdaDamage = d.HitSourceObject as IPandaDamage;
            var skilled     = 0f;

            if (pandaArmor != null && Random.NextFloat() <= pandaArmor.MissChance)
            {
                d.ResultDamage = 0;
                return;
            }

            if (pamdaDamage == null && d.HitSourceType == ModLoader.OnHitData.EHitSourceType.NPC)
            {
                var npc = d.HitSourceObject as NPCBase;
                var inv = ColonistInventory.Get(npc);
                ColonistManager.IncrimentSkill(npc);
                skilled = inv.GetSkillModifier();

                if (inv.Weapon != null && Items.Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var wep))
                {
                    pamdaDamage = wep;
                }
            }

            if (pandaArmor != null && pamdaDamage != null)
            {
                d.ResultDamage = Items.Weapons.WeaponFactory.CalcDamage(pandaArmor, pamdaDamage);
            }
            else if (pandaArmor != null)
            {
                d.ResultDamage = DamageType.Physical.CalcDamage(pandaArmor.ElementalArmor, d.ResultDamage);

                if (pandaArmor.AdditionalResistance.TryGetValue(DamageType.Physical, out var flatResist))
                {
                    d.ResultDamage = d.ResultDamage - d.ResultDamage * flatResist;
                }
            }

            double skillRoll = Pipliz.Random.Next() + skilled;

            if (skillRoll < skilled)
            {
                d.ResultDamage += d.ResultDamage;
            }

            d.ResultDamage = d.ResultDamage - d.ResultDamage * cs.Difficulty.MonsterDamageReduction;

            if (d.ResultDamage < 0)
            {
                d.ResultDamage = 0;
            }

            if (d.HitSourceType == ModLoader.OnHitData.EHitSourceType.NPC)
            {
                var npc = d.HitSourceObject as NPCBase;
                var inv = ColonistInventory.Get(npc);
                inv.IncrimentStat("Damage Done", d.ResultDamage);

                if (skillRoll < skilled)
                {
                    inv.IncrimentStat("Double Damage Hits");
                }
            }

            if (d.ResultDamage >= monster.CurrentHealth)
            {
                monster.OnRagdoll();
                var    rewardMonster = monster as IPandaZombie;
                string monsterType   = "zombie";

                if (rewardMonster != null)
                {
                    monsterType = rewardMonster.MosterType;
                }

                if (monster.OriginalGoal.OwnerIsOnline())
                {
                    if (!string.IsNullOrEmpty(monsterType) &&
                        LootTables.Lookup.TryGetValue(monsterType, out var lootTable))
                    {
                        float luck = 0;

                        if (d.HitSourceObject is ILucky luckSrc)
                        {
                            luck = luckSrc.Luck;
                        }
                        else if ((d.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerClick ||
                                  d.HitSourceType == ModLoader.OnHitData.EHitSourceType.PlayerProjectile) &&
                                 d.HitSourceObject is Players.Player player)
                        {
                            var ps = PlayerState.GetPlayerState(player);

                            foreach (var armor in ps.Armor)
                            {
                                if (Items.Armor.ArmorFactory.ArmorLookup.TryGetValue(armor.Value.Id, out var a))
                                {
                                    luck += a.Luck;
                                }
                            }

                            if (Items.Weapons.WeaponFactory.WeaponLookup.TryGetValue(ps.Weapon.Id, out var w))
                            {
                                luck += w.Luck;
                            }
                        }
                        else if (d.HitSourceType == ModLoader.OnHitData.EHitSourceType.NPC &&
                                 d.HitSourceObject is NPCBase nPC)
                        {
                            var inv = ColonistInventory.Get(nPC);

                            foreach (var armor in inv.Armor)
                            {
                                if (Items.Armor.ArmorFactory.ArmorLookup.TryGetValue(armor.Value.Id, out var a))
                                {
                                    luck += a.Luck;
                                }
                            }

                            if (Items.Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var w))
                            {
                                luck += w.Luck;
                            }
                        }

                        var roll = lootTable.GetDrops(luck);

                        foreach (var item in roll)
                        {
                            monster.OriginalGoal.Stockpile.Add(item.Key, item.Value);
                        }
                    }
                }
            }
        }
        public static void BuildSettlerDetailMenu(ButtonPressCallbackData data, KeyValuePair <string, JobCounts> jobKvp, global::Jobs.IJob job)
        {
            var         inv  = Entities.ColonistInventory.Get(job.NPC);
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("Colonist", data.Player) + " " + inv.ColonistsName + " " + _localizationHelper.LocalizeOrDefault("Details", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new ButtonCallback(jobKvp.Key + ".JobDetailsButton", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
            menu.Items.Add(new Line(UnityEngine.Color.black));

            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Stats"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChance"), UnityEngine.Color.black)),
                                               new Label(new LabelData((inv.GetSkillModifier() * 100) + "%", UnityEngine.Color.black))));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChanceDesc"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 13)));
            ColonistManager.GetSkillInformation(job.NPC, out var nextLevel, out var itt, out var allSkill);
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("ToNextSkillUp"), UnityEngine.Color.black)),
                                               new Label(new LabelData((nextLevel - itt).ToString(), UnityEngine.Color.black))));

            foreach (var statItem in inv.Stats)
            {
                if (ItemTypes.IndexLookup.TryGetIndex(statItem.Key, out var itemIndex))
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
                else
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
            }

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("BonusProcs"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 20)));

            var procItemsHeader = new List <ValueTuple <IItem, int> >();

            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Item"), UnityEngine.Color.black)), 150));
            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 150));
            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Count"), UnityEngine.Color.black)), 150));
            menu.Items.Add(new HorizontalRow(procItemsHeader));

            if (inv.BonusProcs.Count == 0)
            {
                menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("NoneYet"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 20)));
            }

            foreach (var proc in inv.BonusProcs)
            {
                var procItems = new List <ValueTuple <IItem, int> >();
                procItems.Add(ValueTuple.Create <IItem, int>(new ItemIcon(proc.Key), 150));
                procItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ItemTypes.GetType(proc.Key).Name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 150));
                procItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("x " + proc.Value, UnityEngine.Color.black)), 150));
                menu.Items.Add(new HorizontalRow(procItems));
            }

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Equiptment"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));
            List <ValueTuple <IItem, int> > wep = new List <ValueTuple <IItem, int> >();

            wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Weapon"), UnityEngine.Color.black)), 200));
            wep.Add(ValueTuple.Create <IItem, int>(new ItemIcon(inv.Weapon.Id), 200));

            if (Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var wepItem))
            {
                wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(wepItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".RemoveEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
            }
            else
            {
                wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
            }

            menu.Items.Add(new HorizontalRow(wep));

            foreach (var armor in inv.Armor)
            {
                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey(armor.Key.ToString()), UnityEngine.Color.black)), 200));
                items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(armor.Value.Id), 200));

                if (Armor.ArmorFactory.ArmorLookup.TryGetValue(armor.Value.Id, out var arm))
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(arm.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".RemoveEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }

                menu.Items.Add(new HorizontalRow(items));
            }


            NetworkMenuManager.SendServerPopup(data.Player, menu);
        }