예제 #1
0
        public BaseItem PickupItem(int mapItemId, Client c, short mapItemAmount)
        {
            MapItem m = null;

            try
            {
                m = mapItems.Where(x => x.MapItemID == mapItemId).First();
            }
            catch (Exception)
            {
                return null;
            }

            BaseItem item = null;

            if (m.DroppedByCharacterID == 0 || m.DroppedByCharacterID == c.MyCharacter.CharacterId)
            {
                if (m.bType != (byte)bType.Jeon)
                {
                    if (m.ItemID != 0)
                        item = itemDataManager.GetItemByItemID(m.ItemID);
                    else
                        item = itemDataManager.GetItemByReferenceID(m.ReferenceID);

                    BagSlot bagSlot = gameEngine.TryPickToBags(c.MyCharacter.Bags.ToArray(), item);

                    item.Slot = bagSlot.Slot;
                    item.Bag = bagSlot.Bag;

                    mapItemManager.DeleteMapItem(m.MapItemID, 0);
                    mapItems.Remove(m);
                    item.OwnerID = c.MyCharacter.CharacterId;

                    if (item.ItemID != 0)
                        itemDataManager.UpdateItem(item);
                    else
                    {
                        item.ItemID = itemDataManager.InsertItem(item);
                        if (item is Equipment)
                        {
                            // later add chance to get these items blabla
                            Equipment Item = item as Equipment;
                            ImbueStat stat = ImbueStat.None;
                            ImbueItem imbueitem = new ImbueItem
                            {
                                ImbueChance = 1,
                                IncreaseValue = 1,
                            };
                            // Possible plus for drop
                            if (XiahRandom.PercentSuccess(40))
                            {
                                int plus = gameEngine.RandomChance(0, 5);
                                for (int i = 0; i < plus; i++)
                                {
                                    gameEngine.BlackImbue(Item, ref stat, imbueitem, 1);
                                    Item.Plus++;
                                }
                            }

                            if (XiahRandom.PercentSuccess(40))
                            {
                                // Possible slvl for drop
                                int slvl = gameEngine.RandomChance(0, 5);
                                for (int i = 0; i < slvl && !(Item is Cape); i++)
                                {
                                    gameEngine.WhiteImbue(Item, ref stat, imbueitem);
                                    Item.Slvl++;
                                }
                            }

                            item = Item;
                            itemDataManager.UpdateItem(item);
                        }
                    }
                }
                else
                {
                    item = itemDataManager.GetItemByReferenceID(m.ReferenceID);
                    mapItemManager.DeleteMapItem(m.MapItemID, 0);
                    mapItems.Remove(m);

                    item.Amount = mapItemAmount;
                }
            }
            else
            {
                c.Send(PacketEngine.PacketManager.SendPickUpText(0, 0, 0));
                // send pickuperror blabal
            }

            return item;
        }
예제 #2
0
        private void PetGainExperience(Client c, BaseEntity entity, Pet pet)
        {
            if (pet.Level < 200)
            {
                Monster m = null;
                if (entity is Monster)
                    m = entity as Monster;

                long petexp = Math.Abs(pet.CurrentExperience - pet.NegativeExperience);
                bool leveled = false;
                bool evolved = false;

                int experience = m.Experience - pet.Level;

                if (experience < 0)
                    experience = 1;

                if (pet.IsUsingEmpathy)
                {
                    float bonus = (float)(experience * pet.BonusExperience);
                    experience += (int)bonus;
                }

                experience *= ExperienceMultiper;

                if (petexp + experience > pet.ExperienceToLevel)
                {
                    int stat = XiahRandom.Next(0, 4);
                    pet.Level++;
                    int additional = 1;

                    if (pet.Evolution < 3)
                    {
                        if (pet.Level >= pet.EvolutionTable[pet.Evolution].Level)
                        {
                            evolved = true;
                            pet.PetType = pet.EvolutionTable[pet.Evolution].Type;
                            pet.Evolution++;
                            additional += 2 * pet.Evolution;
                        }
                    }

                    switch (stat)
                    {
                        case 0:
                            pet.MaxHealth += (pet.Level * 4) + additional;
                            break;

                        case 1:
                            pet.Damage += (pet.Level * 3) + additional;
                            break;

                        case 2:
                            pet.Defense += (pet.Level * 3) + additional;
                            break;

                        case 3:
                            pet.AttackRating += (pet.Level * 3) + additional;
                            break;
                    }

                    pet.ExperienceToLevel = petManager.GetExperienceToLevelByLevel(pet.Level);
                    pet.NegativeExperience = petManager.GetNegativeExpByLevel(pet.Level);
                    leveled = true;
                    pet.CurHealth = pet.MaxHealth;
                }

                pet.CurrentExperience += experience;

                petManager.UpdatePet(pet);

                byte[] SendPetGainedExperience = PacketManager.SendPetExperienceGained(pet, experience);
                c.Send(SendPetGainedExperience);

                if (leveled)
                {
                    byte[] SendPetLeveled = PacketManager.SendPetLeveled(pet);
                    c.Send(SendPetLeveled);
                }
                if (evolved)
                {
                    byte[] SendPetEvolution = PacketManager.SendPetEvolution(pet);
                    c.Send(SendPetEvolution);
                }
            }
        }
예제 #3
0
        private void ClientLeaveParty(Client c)
        {
            byte[] SendLeaveParty = PacketManager.SendLeaveParty(c.MyCharacter.Party, c.MyCharacter);

            if (c.MyCharacter.Party.MemberCount == 2)
            {
                byte[] SendKillParty = PacketManager.SendKillParty(c.MyCharacter.Party);
                foreach (Character ch in c.MyCharacter.Party.Members)
                {
                    Client member = GetClientByCharacterID(ch.CharacterId);
                    if (member != null)
                    {
                        member.Send(SendLeaveParty);
                        member.Send(SendKillParty);

                        ch.Party = null;
                    }
                }
            }
            else
            {
                c.MyCharacter.Party.Members.Remove(c.MyCharacter);
                c.Send(SendLeaveParty);

                if (c.MyCharacter == c.MyCharacter.Party.Leader)
                {
                    Character newLeader = null;
                    if (c.MyCharacter.Party.Members[1] != c.MyCharacter)
                        newLeader = c.MyCharacter.Party.Members[1];

                    c.MyCharacter.Party.Leader = newLeader;
                    byte[] SendChangeLeader = PacketManager.SendChangePartyLeader(c.MyCharacter.Party);

                    foreach (Character ch in c.MyCharacter.Party.Members)
                    {
                        Client member = GetClientByCharacterID(ch.CharacterId);
                        member.Send(SendLeaveParty);
                        member.Send(SendChangeLeader);

                        ch.Party = c.MyCharacter.Party;
                    }
                }
                else
                {
                    foreach (Character ch in c.MyCharacter.Party.Members)
                    {
                        Client member = GetClientByCharacterID(ch.CharacterId);
                        if (member != null)
                        {
                            member.Send(SendLeaveParty);

                            ch.Party = c.MyCharacter.Party;
                        }
                    }
                }
            }
        }
예제 #4
0
        private bool MoveShopItem(Client c, MoveShopItemInfo m, BaseItem item)
        {
            BaseItem itemunder = null;
            if (m.ItemUnderID != 0)
                itemunder = c.MyCharacter.Shop.Items.First(x => x.ItemID == m.ItemUnderID);

            if (m.ToSlot <= 36)
            {
                if (c.MyCharacter.Shop.MoveItem(c.MyCharacter, item, m.ToSlot, out itemunder))
                {
                    if (itemunder == null)
                    {
                        item.Slot = (byte)(m.ToSlot);

                        itemDataManager.UpdateShopItemById(item);
                    }
                    else
                    {
                        int tempslot;
                        tempslot = item.Slot;
                        item.Slot = itemunder.Slot;
                        itemunder.Slot = (byte)tempslot;

                        itemDataManager.UpdateShopItemById(item);
                        itemDataManager.UpdateShopItemById(itemunder);
                    }

                    byte[] SendRemoveShopItem = PacketManager.SendRemoveShopItem(m.FromSlot, item.ItemID, item.Amount);
                    c.Send(SendRemoveShopItem);

                    if (itemunder != null)
                    {
                        byte[] SendRemoveShopItemUnder = PacketManager.SendRemoveShopItem(m.ToSlot, itemunder.ItemID, itemunder.Amount);
                        c.Send(SendRemoveShopItemUnder);

                        byte[] SendAddShopItemUnder = PacketManager.SendAddItemToShop(itemunder, itemunder.SellPrice);
                        c.Send(SendAddShopItemUnder);
                    }

                    byte[] SendAddShopItem = PacketManager.SendAddItemToShop(item, item.SellPrice);
                    c.Send(SendAddShopItem);
                    return true;
                }
            }

            return false;
        }
예제 #5
0
        private bool MoveWarehouseItem(Client c, MoveWarehouseItemInfo m, BaseItem item)
        {
            BaseItem itemunder = null;
            if (m.ItemUnderID != 0)
                itemunder = c.MyCharacter.Warehouse.Items.First(x => x.ItemID == m.ItemUnderID);

            if (m.ToSlot <= 65)
            {
                if (c.MyCharacter.Warehouse.MoveItem(c.MyCharacter, item, m.ToSlot, out itemunder))
                {
                    if (itemunder == null)
                    {
                        item.Slot = (byte)(m.ToSlot);

                        itemDataManager.UpdateItem(item);
                    }
                    else
                    {
                        int tempslot;
                        tempslot = item.Slot;
                        item.Slot = itemunder.Slot;
                        itemunder.Slot = (byte)tempslot;

                        itemDataManager.UpdateItem(item);
                        itemDataManager.UpdateItem(itemunder);
                    }

                    byte[] SendRemoveWarehouseItem = PacketManager.SendWarehouseRemoveItem(m.FromSlot, item.ItemID);
                    c.Send(SendRemoveWarehouseItem);

                    byte[] SendAddWarehouseItem = PacketManager.SendAddItemToWarehouse(2, item);
                    c.Send(SendAddWarehouseItem);

                    if (itemunder != null)
                    {
                        byte[] SendRemoveWarehouseItemUnder = PacketManager.SendWarehouseRemoveItem(m.ToSlot, itemunder.ItemID);
                        c.Send(SendRemoveWarehouseItemUnder);

                        byte[] SendAddWarehouseItemUnder = PacketManager.SendAddItemToWarehouse(2, itemunder);
                        c.Send(SendAddWarehouseItemUnder);
                    }

                    return true;
                }
            }

            return false;
        }
예제 #6
0
        private void CharacterGainExperience(Client c, BaseEntity entity, Character ch, bool gainedExp)
        {
            if (ch.Party != null && gainedExp == false)
            {
                foreach (Character m in ch.Party.Members)
                {
                    Client member = GetClientByCharacterID(m.CharacterId);
                    CharacterGainExperience(member, entity, m, true);
                }
                return;
            }
            else if (ch.Level < 200)
            {
                Monster m = null;
                if (entity is Monster)
                    m = entity as Monster;

                long charexp = Math.Abs(ch.CurrentExp - ch.NegativeExp);
                bool leveled = false;
                bool training = false;
                int experience = m.Experience - ch.Level;
                if (experience < 0)
                    experience = 1;
                experience = experience * ExperienceMultiper;

                if (ch.Party != null)
                {
                    float maxExp = 1.0f;
                    float divider = 0.1f;
                    divider = maxExp - (divider * ch.Party.MemberCount);

                    experience = (int)(experience * divider);

                    if (experience < 0)
                        experience = 1;
                }

                if (charexp + experience > ch.ExpToTraining)
                {
                    ch.TrainingPoint++;
                    ch.GainedTrainings++;
                    ch.TpLevel++;
                    ch.ExpToTraining = characterManager.GetExperienceToTpByTpLevel(ch.TpLevel);
                    training = true;

                    c.MyCharacter.CalculateTotalStats();
                    c.MyCharacter.CurrentHp = c.MyCharacter.MaxHp;
                    c.MyCharacter.CurrentMana = c.MyCharacter.MaxMana;
                }
                if (charexp + experience > ch.ExpToLevel)
                {
                    ch.StatPoint += (short)ch.GetStatPointsPerLevel();
                    ch.Level++;
                    ch.ExpToLevel = characterManager.GetExperienceToLevelByLevel(ch.Level);
                    ch.NegativeExp = characterManager.GetNegativeExpByLevel(ch.Level);
                    leveled = true;

                    c.MyCharacter.CalculateTotalStats();
                    c.MyCharacter.CurrentHp = c.MyCharacter.MaxHp;
                    c.MyCharacter.CurrentMana = c.MyCharacter.MaxMana;

                    if (ch.Party != null)
                    {
                        foreach (Character p in c.MyCharacter.Party.Members)
                        {
                            Client playerClient = GetClientByCharacterID(p.CharacterId);
                            playerClient.Send(PacketManager.SendParty(c.MyCharacter.Party));
                        }
                    }
                }

                ch.CurrentExp += experience;

                characterManager.UpdateCharacter(ch);

                byte[] SendExpEffectPacket = PacketManager.SendExpEffectPacket(m);
                c.Send(SendExpEffectPacket);

                byte[] SendExpMaybe = PacketManager.SendExperience(ch, experience, 0, leveled, training);
                c.Send(SendExpMaybe);

                byte[] bufferSendStats = PacketManager.SendStats(c.MyCharacter);
                c.Send(bufferSendStats);
            }
        }
예제 #7
0
        private bool LearnSkill(Client c, BaseItem item, bool removeItem, BaseSkill skill, BookItem book)
        {
            short test = 0;

            if (!c.MyCharacter.ContainSkill(skill.SkillID, skill.SkillLevel) && c.MyCharacter.TrainingPoint >= skill.RequiredTraining && c.MyCharacter.Level >= skill.RequiredLevel && c.MyCharacter.Strength >= skill.RequiredStrength && c.MyCharacter.Stamina >= skill.RequiredStamina && c.MyCharacter.Dexterity >= skill.RequiredDexterity && c.MyCharacter.Energy >= skill.RequiredEnergy)
            {
                if (item.RequiredClass == 0 || c.MyCharacter.Class == item.RequiredClass)
                {
                    if (book.SkillLevel == 1)
                    {
                        characterManager.LearnSkill(c.MyCharacter.CharacterId, skill.SkillID, skill.SkillLevel, ref test);
                        c.MyCharacter.TrainingPoint = test;

                        characterManager.UpdateCharacter(c.MyCharacter);

                        c.MyCharacter.SkillList.Add(skill);

                        byte[] LearnSkill = PacketManager.SendLearnSkill(0, skill.SkillID, skill.SkillLevel, skill.RequiredTraining, c.MyCharacter.TrainingPoint);
                        c.Send(LearnSkill);

                        c.Send(PacketManager.SendSkillSomething());

                        removeItem = true;
                    }
                    else
                    {
                        if (c.MyCharacter.ContainSkill(skill.SkillID, skill.SkillLevel - 1))
                        {
                            characterManager.LearnSkill(c.MyCharacter.CharacterId, skill.SkillID, skill.SkillLevel, ref test);
                            c.MyCharacter.UpdateSkill(skill);
                            c.MyCharacter.TrainingPoint = test;

                            characterManager.UpdateCharacter(c.MyCharacter);

                            byte[] LearnSkill = PacketManager.SendLearnSkill(0, skill.SkillID, skill.SkillLevel, skill.RequiredTraining, c.MyCharacter.TrainingPoint);
                            c.Send(LearnSkill);

                            c.Send(PacketManager.SendSkillSomething());

                            removeItem = true;
                        }
                        else
                        {
                            c.Send(PacketManager.SendSkillError(SkillLearnError.NeedMartialArts));
                        }
                    }
                }
                else
                {
                    c.Send(PacketManager.SendSkillError(SkillLearnError.WrongClass));
                }
            }
            else
            {
                byte error = 0;

                if (c.MyCharacter.TrainingPoint <= skill.RequiredTraining)
                    error = 9;
                if (c.MyCharacter.Level <= skill.RequiredLevel)
                    error = 5;
                if (c.MyCharacter.Strength <= skill.RequiredStrength)
                    error = 2;
                if (c.MyCharacter.Dexterity <= skill.RequiredDexterity)
                    error = 1;
                if (c.MyCharacter.Stamina <= skill.RequiredStamina)
                    error = 3;
                if (c.MyCharacter.Energy <= skill.RequiredEnergy)
                    error = 4;
                if (c.MyCharacter.Class != item.RequiredClass && item.RequiredClass != 0)
                    error = 8;
                if (c.MyCharacter.ContainSkill(skill.SkillID, skill.SkillLevel))
                    error = 6;

                c.Send(PacketManager.SendSkillError((SkillLearnError)error));
                // send not enought stats/tps
            }
            return removeItem;
        }
예제 #8
0
        private void HandleUnEquipItem(Client c, MoveItemInfo m, BaseItem item)
        {
            try
            {
                MapEngine mapEngine = GetMapEngine(c.MyCharacter.MapId);
                Client[] clients = GetClientsForChars(mapEngine.GetCharactersInRange(c.MyCharacter.Position, 150).ToArray());

                if (m.ToBag != 255 && m.ToSlot != 255)
                {
                    if (!c.MyCharacter.Bags[m.ToBag - 1].IsSlotValid(item, m.ToSlot))
                    {
                        throw new InvalidItemSlotException("NO PUT ON EDGE PUJJ");
                    }

                    if (!c.MyCharacter.Bags[m.ToBag - 1].CheckSlot(item, m.ToSlot))
                    {
                        switch (item.Slot)
                        {
                            case (byte)Slot.Weapon: // Hand
                                c.MyCharacter.Hand = null;
                                break;

                            case (byte)Slot.Hat: // Hat
                                c.MyCharacter.Head = null;
                                break;

                            case (byte)Slot.Armor: // Armor
                                c.MyCharacter.Body = null;
                                break;

                            case (byte)Slot.Shoes: // Shoes
                                c.MyCharacter.Feet = null;
                                break;

                            case (byte)Slot.Ring:
                                c.MyCharacter.Ring = null;
                                break;

                            case (byte)Slot.Necklace:
                                c.MyCharacter.Necklace = null;
                                break;

                            case (byte)Slot.Cape:
                                c.MyCharacter.Cape = null;
                                break;

                            case (byte)Slot.Mirror:
                                c.MyCharacter.Mirror = null;
                                break;

                            default:
                                break;
                        }

                        item.Bag = m.ToBag;
                        item.Slot = m.ToSlot;
                        c.MyCharacter.Bags[m.ToBag - 1].AddItem(item);
                        itemDataManager.UpdateItem(item);

                        byte[] SendMoveItem = PacketManager.SendMoveItem(m, 0);
                        c.Send(SendMoveItem);

                        byte[] SendNewStats = PacketManager.SendStats(c.MyCharacter);
                        c.Send(SendNewStats);

                        byte[] SendNewVisuals = PacketManager.SendSpawnPlayers(c.MyCharacter);
                        SendToClients(SendNewVisuals, clients);
                    }
                    else
                    {
                        byte[] SendError = PacketManager.SendMoveItem(m, 2);
                        c.Send(SendError);
                    }
                }
            }
            catch
            {
                byte[] SendError = PacketManager.SendMoveItem(m, 2);
                c.Send(SendError);
            }
        }
예제 #9
0
        private void HandleEquipItem(Client c, MoveItemInfo m, BaseItem item)
        {
            try
            {
                BaseItem conflict = null;
                MapEngine mapEngine = GetMapEngine(c.MyCharacter.MapId);
                Client[] clients = GetClientsForChars(mapEngine.GetCharactersInRange(c.MyCharacter.Position, 150).ToArray());

                switch (m.ToSlot)
                {
                    case (byte)Slot.Weapon: // Hand
                        conflict = c.MyCharacter.Hand;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Hand = (Hand)item;
                        break;

                    case (byte)Slot.Hat: // Hat
                        conflict = c.MyCharacter.Head;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Head = (Head)item;
                        break;

                    case (byte)Slot.Armor: // Armor
                        conflict = c.MyCharacter.Body;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Body = (Body)item;
                        break;

                    case (byte)Slot.Shoes: // Shoes
                        conflict = c.MyCharacter.Feet;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Feet = (Feet)item;
                        break;

                    case (byte)Slot.Ring:
                        conflict = c.MyCharacter.Ring;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Ring = (Ring)item;
                        break;

                    case (byte)Slot.Necklace:
                        conflict = c.MyCharacter.Necklace;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Necklace = (Necklace)item;
                        break;

                    case (byte)Slot.Cape:
                        conflict = c.MyCharacter.Cape;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Cape = (Cape)item;
                        break;

                    case (byte)Slot.Mirror:
                        conflict = c.MyCharacter.Mirror;
                        if (conflict != null)
                        {
                            conflict.Slot = item.Slot;
                            conflict.Bag = item.Bag;
                        }
                        c.MyCharacter.Mirror = (Mirror)item;
                        break;
                    default:
                        break;
                }

                if (conflict != null)
                {
                    c.MyCharacter.Bags[m.FromBag - 1].AddItem(conflict);
                    itemDataManager.UpdateItem(conflict);
                }

                c.MyCharacter.Bags[m.FromBag - 1].RemoveItem(item);
                itemDataManager.UpdateItem(item);

                byte[] SendEquipItem = PacketManager.SendMoveItem(m, 0);
                c.Send(SendEquipItem);

                byte[] SendNewStats = PacketManager.SendStats(c.MyCharacter);
                c.Send(SendNewStats);

                if (c.MyCharacter.ImperialSet != ImperialSet.None)
                {
                    SendCommandHelp(string.Format("Wearing set: {0}", c.MyCharacter.ImperialSet.ToString()), c);
                }

                byte[] SendNewVisuals = PacketManager.SendSpawnPlayers(c.MyCharacter);
                SendToClients(SendNewVisuals, clients);
            }
            catch (RequiredClassException)
            {
                byte[] SendEquipError = PacketManager.SendMoveItem(m, 3);
                c.Send(SendEquipError);
            }
        }
예제 #10
0
        public void SendCommandHelp(string message, Client c)
        {
            Character fakeChar = new Character { CharacterId = -1, Name = "CONSOLE" };

            ChatMessageInfo msg = new ChatMessageInfo { Message = message, Type = ChatType.Guild, TargetName = "" };
            byte[] packet = PacketManager.SendChatMessage(fakeChar, msg);
            c.Send(packet);
        }