Exemplo n.º 1
0
        public void PickUpItem(Companion ob)
        {
            if (!CanPickUpItem(ob.CompanionOwner))
            {
                return;
            }

            long amount = 0;

            if (Account != null && Item.Info.Effect == ItemEffect.Gold && Account.GuildMember != null && Account.GuildMember.Guild.GuildTax > 0)
            {
                amount = (long)Math.Ceiling(Item.Count * Account.GuildMember.Guild.GuildTax);
            }

            ItemCheck check = new ItemCheck(Item, Item.Count - amount, Item.Flags, Item.ExpireTime);

            if (ob.CanGainItems(false, check))
            {
                if (amount > 0)
                {
                    Item.Count -= amount;

                    Account.GuildMember.Guild.GuildFunds  += amount;
                    Account.GuildMember.Guild.DailyGrowth += amount;

                    Account.GuildMember.Guild.DailyContribution += amount;
                    Account.GuildMember.Guild.TotalContribution += amount;

                    Account.GuildMember.DailyContribution += amount;
                    Account.GuildMember.TotalContribution += amount;

                    foreach (GuildMemberInfo member in Account.GuildMember.Guild.Members)
                    {
                        if (member.Account.Connection?.Player == null)
                        {
                            continue;
                        }

                        member.Account.Connection.Enqueue(new S.GuildMemberContribution {
                            Index = Account.GuildMember.Index, Contribution = amount, ObserverPacket = false
                        });
                    }
                }

                Item.UserTask?.Objects.Remove(this);

                ob.GainItem(Item);
                Despawn();
                return;
            }

            //Get Max Carry of type
            //Reduce Amount by type.
            //Send updated floor counts
            //Gain New / partial items
            return;
        }
Exemplo n.º 2
0
        private void DoActions(PlayerObject ob, NPCPage page)
        {
            foreach (NPCAction action in page.Actions)
            {
                switch (action.ActionType)
                {
                case NPCActionType.Teleport:
                    if (action.MapParameter1 == null)
                    {
                        return;
                    }

                    Map map = SEnvir.GetMap(action.MapParameter1);

                    if (action.IntParameter1 == 0 && action.IntParameter2 == 0)
                    {
                        ob.Teleport(map, map.GetRandomLocation());
                    }
                    else
                    {
                        ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2));
                    }
                    break;

                case NPCActionType.TakeGold:
                    ob.Gold -= action.IntParameter1;
                    ob.GoldChanged();
                    break;

                case NPCActionType.ChangeElement:
                    UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon];

                    S.ItemStatsChanged result = new S.ItemStatsChanged {
                        GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats()
                    };
                    result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement];

                    weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine);
                    weapon.StatsChanged();
                    ob.RefreshStats();

                    ob.Enqueue(result);
                    break;

                case NPCActionType.ChangeHorse:
                    ob.Character.Account.Horse = (HorseType)action.IntParameter1;

                    ob.RemoveMount();

                    ob.RefreshStats();

                    if (ob.Character.Account.Horse != HorseType.None)
                    {
                        ob.Mount();
                    }
                    break;

                case NPCActionType.GiveGold:

                    long gold = ob.Gold + action.IntParameter1;

                    ob.Gold = (long)gold;
                    ob.GoldChanged();

                    break;

                case NPCActionType.Marriage:
                    ob.MarriageRequest();
                    break;

                case NPCActionType.Divorce:
                    ob.MarriageLeave();
                    break;

                case NPCActionType.RemoveWeddingRing:
                    ob.MarriageRemoveRing();
                    break;

                case NPCActionType.GiveItem:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero);

                    if (!ob.CanGainItems(false, check))
                    {
                        continue;
                    }

                    while (check.Count > 0)
                    {
                        ob.GainItem(SEnvir.CreateFreshItem(check));
                    }

                    break;

                case NPCActionType.TakeItem:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    ob.TakeItem(action.ItemParameter1, action.IntParameter1);
                    break;

                case NPCActionType.ResetWeapon:
                    ob.NPCResetWeapon();
                    break;

                case NPCActionType.GiveItemExperience:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero);

                    if (!ob.CanGainItems(false, check))
                    {
                        continue;
                    }

                    while (check.Count > 0)
                    {
                        UserItem item = SEnvir.CreateFreshItem(check);

                        item.Experience = action.IntParameter2;

                        if (item.Experience >= Globals.AccessoryExperienceList[item.Level])
                        {
                            item.Experience -= Globals.AccessoryExperienceList[item.Level];
                            item.Level++;

                            item.Flags |= UserItemFlags.Refinable;
                        }

                        ob.GainItem(item);
                    }

                    break;

                case NPCActionType.SpecialRefine:
                    ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1);
                    break;

                case NPCActionType.Rebirth:
                    if (ob.Level >= 86 + ob.Character.Rebirth)
                    {
                        ob.NPCRebirth();
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private bool CheckPage(PlayerObject ob, NPCPage page, out NPCPage failPage)
        {
            failPage = null;
            foreach (NPCCheck check in page.Checks)
            {
                failPage = check.FailPage;
                UserItem weap;
                switch (check.CheckType)
                {
                case NPCCheckType.Level:
                    if (!Compare(check.Operator, ob.Level, check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.Class:
                    if (!Compare(check.Operator, (int)ob.Class, check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.Gold:
                    if (!Compare(check.Operator, ob.Gold, check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.HasWeapon:
                    if (ob.Equipment[(int)EquipmentSlot.Weapon] != null != (check.Operator == Operator.Equal))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.WeaponLevel:
                    if (!Compare(check.Operator, ob.Equipment[(int)EquipmentSlot.Weapon].Level, check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.WeaponCanRefine:
                    if ((ob.Equipment[(int)EquipmentSlot.Weapon].Flags & UserItemFlags.Refinable) == UserItemFlags.Refinable != (check.Operator == Operator.Equal))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.WeaponAddedStats:
                    if (!Compare(check.Operator, ob.Equipment[(int)EquipmentSlot.Weapon].Stats[check.StatParameter1], check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.WeaponElement:
                    weap = ob.Equipment[(int)EquipmentSlot.Weapon];

                    Stat element;
                    int  value = 0;

                    switch ((Element)check.IntParameter1)
                    {
                    case Element.None:
                        value += weap.Stats.GetWeaponElementValue();
                        value += weap.Info.Stats.GetWeaponElementValue();
                        break;

                    case Element.Fire:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.FireAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Ice:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.IceAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Lightning:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.LightningAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Wind:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.WindAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Holy:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.HolyAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Dark:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.DarkAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }

                        break;

                    case Element.Phantom:
                        element = weap.Stats.GetWeaponElement();

                        if (element == Stat.None)
                        {
                            element = weap.Info.Stats.GetWeaponElement();
                        }

                        if (element == Stat.PhantomAttack)
                        {
                            value += weap.Stats.GetWeaponElementValue();
                            value += weap.Info.Stats.GetWeaponElementValue();
                        }
                        break;
                    }


                    if (!Compare(check.Operator, value, check.IntParameter2))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.PKPoints:
                    if (!Compare(check.Operator, ob.Stats[Stat.PKPoint], check.IntParameter1 == 0 ? Config.RedPoint : check.IntParameter1) && ob.Stats[Stat.Redemption] == 0)
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.Horse:
                    if (!Compare(check.Operator, (int)ob.Character.Account.Horse, check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.Marriage:
                    if (check.Operator == Operator.Equal)
                    {
                        if (ob.Character.Partner == null)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (ob.Character.Partner != null)
                        {
                            return(false);
                        }
                    }
                    break;

                case NPCCheckType.WeddingRing:
                    if (check.Operator == Operator.Equal)
                    {
                        if (ob.Equipment[(int)EquipmentSlot.RingL] == null || (ob.Equipment[(int)EquipmentSlot.RingL].Flags & UserItemFlags.Marriage) != UserItemFlags.Marriage)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (ob.Equipment[(int)EquipmentSlot.RingL] != null && (ob.Equipment[(int)EquipmentSlot.RingL].Flags & UserItemFlags.Marriage) == UserItemFlags.Marriage)
                        {
                            return(false);
                        }
                    }
                    break;

                case NPCCheckType.HasItem:
                    if (check.ItemParameter1 == null)
                    {
                        continue;
                    }
                    if (!Compare(check.Operator, ob.GetItemCount(check.ItemParameter1), check.IntParameter1))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.CanGainItem:
                    if (check.ItemParameter1 == null)
                    {
                        continue;
                    }

                    ItemCheck itemCheck = new ItemCheck(check.ItemParameter1, check.IntParameter1, UserItemFlags.None, TimeSpan.Zero);

                    if (!ob.CanGainItems(false, itemCheck))
                    {
                        return(false);
                    }
                    break;

                case NPCCheckType.CanResetWeapon:
                    if (check.Operator == Operator.Equal)
                    {
                        if (SEnvir.Now < ob.Equipment[(int)EquipmentSlot.Weapon].ResetCoolDown)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (SEnvir.Now >= ob.Equipment[(int)EquipmentSlot.Weapon].ResetCoolDown)
                        {
                            return(false);
                        }
                    }
                    break;

                case NPCCheckType.Random:
                    if (!Compare(check.Operator, SEnvir.Random.Next(check.IntParameter1), check.IntParameter2))
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        private void DoActions(PlayerObject ob, NPCPage page)
        {
            foreach (NPCAction action in page.Actions)
            {
                switch (action.ActionType)
                {
                case NPCActionType.Teleport:
                    if (action.MapParameter1 == null && action.InstanceParameter1 == null)
                    {
                        return;
                    }

                    if (action.InstanceParameter1 != null)
                    {
                        if (ob.CurrentMap.Instance != null)
                        {
                            return;
                        }

                        var index = SEnvir.LoadInstance(action.InstanceParameter1);

                        if (index == null)
                        {
                            return;
                        }

                        ob.Teleport(action.InstanceParameter1.ConnectRegion, action.InstanceParameter1, index.Value);
                    }
                    else
                    {
                        Map map = SEnvir.GetMap(action.MapParameter1);

                        if (action.IntParameter1 == 0 && action.IntParameter2 == 0)
                        {
                            ob.Teleport(map, map.GetRandomLocation());
                        }
                        else
                        {
                            ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2));
                        }
                    }
                    break;

                case NPCActionType.TakeGold:
                    ob.Gold.Amount -= action.IntParameter1;
                    ob.GoldChanged();
                    break;

                case NPCActionType.ChangeElement:
                    UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon];

                    S.ItemStatsChanged result = new S.ItemStatsChanged {
                        GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats()
                    };
                    result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement];

                    weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine);
                    weapon.StatsChanged();
                    ob.RefreshStats();

                    ob.Enqueue(result);
                    break;

                case NPCActionType.ChangeHorse:
                    ob.Character.Account.Horse = (HorseType)action.IntParameter1;

                    ob.RemoveMount();

                    ob.RefreshStats();

                    if (ob.Character.Account.Horse != HorseType.None)
                    {
                        ob.Mount();
                    }
                    break;

                case NPCActionType.GiveGold:

                    long gold = ob.Gold.Amount + action.IntParameter1;

                    ob.Gold.Amount = (long)gold;
                    ob.GoldChanged();

                    break;

                case NPCActionType.Marriage:
                    ob.MarriageRequest();
                    break;

                case NPCActionType.Divorce:
                    ob.MarriageLeave();
                    break;

                case NPCActionType.RemoveWeddingRing:
                    ob.MarriageRemoveRing();
                    break;

                case NPCActionType.GiveItem:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero);

                    if (!ob.CanGainItems(false, check))
                    {
                        continue;
                    }

                    while (check.Count > 0)
                    {
                        ob.GainItem(SEnvir.CreateFreshItem(check));
                    }

                    break;

                case NPCActionType.TakeItem:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    ob.TakeItem(action.ItemParameter1, action.IntParameter1);
                    break;

                case NPCActionType.ResetWeapon:
                    ob.NPCResetWeapon();
                    break;

                case NPCActionType.GiveItemExperience:
                    if (action.ItemParameter1 == null)
                    {
                        continue;
                    }

                    check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero);

                    if (!ob.CanGainItems(false, check))
                    {
                        continue;
                    }

                    while (check.Count > 0)
                    {
                        UserItem item = SEnvir.CreateFreshItem(check);

                        item.Experience = action.IntParameter2;

                        if (item.Experience >= Globals.AccessoryExperienceList[item.Level])
                        {
                            item.Experience -= Globals.AccessoryExperienceList[item.Level];
                            item.Level++;

                            item.Flags |= UserItemFlags.Refinable;
                        }

                        ob.GainItem(item);
                    }

                    break;

                case NPCActionType.SpecialRefine:
                    ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1);
                    break;

                case NPCActionType.Rebirth:
                    if (ob.Level >= 86 + ob.Character.Rebirth)
                    {
                        ob.NPCRebirth();
                    }
                    break;

                case NPCActionType.GiveCurrency:
                {
                    if (action.StringParameter1 == null)
                    {
                        continue;
                    }

                    var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase));
                    if (info == null)
                    {
                        continue;
                    }

                    var userCurrency = ob.GetCurrency(info);

                    var amount = userCurrency.Amount + action.IntParameter1;

                    userCurrency.Amount = amount;
                    ob.CurrencyChanged(userCurrency);
                }
                break;

                case NPCActionType.TakeCurrency:
                {
                    if (action.StringParameter1 == null)
                    {
                        continue;
                    }

                    var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase));
                    if (info == null)
                    {
                        continue;
                    }

                    var userCurrency = ob.GetCurrency(info);

                    var amount = userCurrency.Amount - action.IntParameter1;

                    userCurrency.Amount = amount;
                    ob.CurrencyChanged(userCurrency);
                }
                break;
                }
            }
        }