Example #1
0
        static void Main(string[] args)
        {
            PetStruct dog = new PetStruct();

            dog.Type   = PetType.Dog;
            dog.Legs   = 4;
            dog.HasFur = true;
            Console.WriteLine("A " + dog.Type + " has " + dog.Legs + " legs");

            PetClass duck = new PetClass();

            duck.Type   = PetType.Duck;
            duck.Legs   = 2;
            duck.HasFur = false;
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs + " legs");

            //MultiplyLegs(dog, duck);
            //Console.WriteLine("A " + dog.Type + " has " + dog.Legs);
            //Console.WriteLine("A " + duck.Type + " has " + duck.Legs);

            PetStruct copiedDog  = dog;
            PetClass  copiedDuck = duck;

            copiedDog.Legs  = copiedDog.Legs * 2;
            copiedDuck.Legs = copiedDuck.Legs * 2;

            Console.WriteLine("A " + dog.Type + " has " + dog.Legs);
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs);

            Console.WriteLine("A " + copiedDog.Type + " has " + copiedDog.Legs);
            Console.WriteLine("A " + copiedDuck.Type + " has " + copiedDuck.Legs);

            Console.ReadLine();
        }
Example #2
0
        public static PetStruct GetPetStruct(RealmManager manager, Family?petFamily, Rarity rarity)
        {
            Random           rand    = new Random((int)DateTime.Now.Ticks);
            List <PetStruct> structs = new List <PetStruct>();

            Rarity petRarity = rarity;

            if (rarity == Rarity.Uncommon)
            {
                petRarity = Rarity.Common;
            }
            else if (rarity == Rarity.Legendary)
            {
                petRarity = Rarity.Rare;
            }

            foreach (var x in manager.GameData.TypeToPet)
            {
                if (petFamily == null && x.Value.PetRarity == petRarity)
                {
                    structs.Add(x.Value);
                    continue;
                }
                if (x.Value.PetFamily == petFamily && x.Value.PetRarity == petRarity)
                {
                    structs.Add(x.Value);
                }
            }

            PetStruct petStruct = structs[rand.Next(structs.Count)];

            return(petStruct);
        }
Example #3
0
        private void Evolve(Client client, Pet pet1, Pet pet2)
        {
            int l1    = pet1.FirstPetLevel.Level == 1 ? 1 : pet1.FirstPetLevel.Level / 2;
            int l2    = pet2.FirstPetLevel.Level == 1 ? 1 : pet2.FirstPetLevel.Level / 2;
            int level = l1 + l2 + 20;

            PetStruct s = null;

            pet1.EvolveResult(level, (int)pet1.PetRarity + 1, ref s);

            if (s == null)
            {
                return;
            }
            PetSkin skin = client.Manager.GameData.IdToPetSkin[s.DefaultSkin];

            client.Manager.Database.DoActionAsync(db =>
            {
                var cmd         = db.CreateQuery();
                cmd.CommandText = "UPDATE pets SET rarity=rarity+1, maxLevel=@level, skinName=@skinName, skin=@skinId, objType=@objType WHERE petId=@petId1 AND accId=@accId;";
                cmd.Parameters.AddWithValue("@accId", client.Account.AccountId);
                cmd.Parameters.AddWithValue("@petId1", pet1.PetId);
                cmd.Parameters.AddWithValue("@level", level);
                cmd.Parameters.AddWithValue("@skinName", skin.DisplayId);
                cmd.Parameters.AddWithValue("@skinId", skin.ObjectType);
                cmd.Parameters.AddWithValue("@objType", s.ObjectType);
                cmd.ExecuteNonQuery();

                cmd             = db.CreateQuery();
                cmd.CommandText = "DELETE FROM pets WHERE accId=@accId AND petId=@petId2;";
                cmd.Parameters.AddWithValue("@accId", client.Account.AccountId);
                cmd.Parameters.AddWithValue("@petId2", pet2.PetId);
                cmd.ExecuteNonQuery();
            });
        }
Example #4
0
        static void MultiplyLegs(PetStruct petStruct, PetClass petClass)
        {
            petStruct.Legs = petStruct.Legs * 2;
            petClass.Legs  = petClass.Legs * 2;

            Console.WriteLine("Internal method) A " + petStruct.Type + " has " + petStruct.Legs);
            Console.WriteLine("Internal method) A " + petClass.Type + " has " + petClass.Legs);
        }
Example #5
0
        //Method to change attribute in the given intance

        static void MultipliedLeg(PetStruct dogLeg, PetClass duckLeg)
        {
            dogLeg.legs  = dogLeg.legs * 2;
            duckLeg.legs = duckLeg.legs * 2;

            Console.WriteLine("Internal Method- {0}", dogLeg.legs);
            Console.WriteLine("Internal Method- {0}", duckLeg.legs);
        }
Example #6
0
        public void EvolveResult(int level, int rarity, ref PetStruct newPetStruct)
        {
            FuseResult(level, rarity);
            PetStruct s = GetPetStruct(Manager, PetFamily, (Rarity)rarity);

            this.Skin    = Manager.GameData.IdToPetSkin[s.DefaultSkin].DisplayId;
            this.SkinId  = Manager.GameData.IdToPetSkin[s.DefaultSkin].ObjectType;
            newPetStruct = s;
        }
Example #7
0
        private static List <AbilityItem> GetPetAbilites(Item egg, PetStruct petStruct)
        {
            List <Ability> abilities = new List <Ability>()
            {
                Ability.AttackClose,
                Ability.AttackFar,
                Ability.AttackMid,
                Ability.Decoy,
                Ability.Electric,
                Ability.Heal,
                Ability.MagicHeal,
                Ability.RisingFury,
                Ability.Savage
            };

            Random             rand = new Random((int)DateTime.Now.Ticks);
            List <AbilityItem> ret  = new List <AbilityItem>(3);
            int power = 1;

            switch (egg.Rarity)
            {
            case Rarity.Uncommon:
                power = 30;
                break;

            case Rarity.Rare:
                power = 50;
                break;

            case Rarity.Legendary:
                power = 70;
                break;
            }

            for (int i = 0; i < 3; i++)
            {
                if (i == 0 && petStruct.FirstAbility != null)
                {
                    ret.Add(new AbilityItem
                    {
                        Power  = power,
                        Points = 0,
                        Type   = (int)petStruct.FirstAbility
                    });

                    abilities.Remove((Ability)petStruct.FirstAbility);
                }
                else
                {
                    Ability ability = abilities[rand.Next(abilities.Count)];
                    ret.Add(new AbilityItem
                    {
                        Power  = power,
                        Points = 0,
                        Type   = (int)ability
                    });

                    if (ability == Ability.AttackClose || ability == Ability.AttackFar || ability == Ability.AttackMid)
                    {
                        abilities.Remove(Ability.AttackClose);
                        abilities.Remove(Ability.AttackFar);
                        abilities.Remove(Ability.AttackMid);
                    }
                    else
                    {
                        abilities.Remove(ability);
                    }
                }
            }


            return(ret);
        }
Example #8
0
        public static void Create(RealmManager manager, Player player, Item egg)
        {
            manager.Database.AddDatabaseOperation(db =>
            {
                PetStruct petStruct = GetPetStruct(manager, egg.Family, (Rarity)egg.Rarity);
                PetSkin skin        = manager.GameData.IdToPetSkin[petStruct.DefaultSkin];

                PetItem item = new PetItem
                {
                    InstanceId = db.GetNextPetId(player.AccountId),
                    Rarity     = (int)egg.Rarity,
                    SkinName   = skin.DisplayId,
                    Skin       = skin.ObjectType,
                    Type       = petStruct.ObjectType,
                    Abilities  = GetPetAbilites(egg, petStruct),
                };

                switch (item.Rarity)
                {
                case 1:
                    item.MaxAbilityPower     = 50;
                    item.Abilities[0].Power  = 30;
                    item.Abilities[0].Points = 2080;
                    item.Abilities[1].Power  = 11;
                    item.Abilities[1].Points = 290;
                    item.Abilities[2].Power  = 1;
                    item.Abilities[2].Points = 0;
                    break;

                case 2:
                    item.MaxAbilityPower     = 70;
                    item.Abilities[0].Power  = 50;
                    item.Abilities[0].Points = 10607;
                    item.Abilities[1].Power  = 30;
                    item.Abilities[1].Points = 2080;
                    item.Abilities[2].Power  = 1;
                    item.Abilities[2].Points = 0;
                    break;

                case 3:
                    item.MaxAbilityPower     = 90;
                    item.Abilities[0].Power  = 70;
                    item.Abilities[0].Points = 50355;
                    item.Abilities[1].Power  = 50;
                    item.Abilities[1].Points = 10607;
                    item.Abilities[2].Power  = 30;
                    item.Abilities[2].Points = 2080;
                    break;

                case 4:
                    item.MaxAbilityPower     = 100;
                    item.Abilities[0].Power  = 90;
                    item.Abilities[0].Points = 235610;
                    item.Abilities[1].Power  = 70;
                    item.Abilities[1].Points = 50354;
                    item.Abilities[2].Power  = 50;
                    item.Abilities[2].Points = 10607;
                    break;

                default:
                    item.MaxAbilityPower     = 30;
                    item.Abilities[0].Power  = 1;
                    item.Abilities[0].Points = 0;
                    item.Abilities[1].Power  = 1;
                    item.Abilities[1].Points = 0;
                    item.Abilities[2].Power  = 1;
                    item.Abilities[2].Points = 0;
                    break;
                }

                Pet pet = new Pet(manager, item, null);
                int x;
                int y;
                Random rand = new Random((int)DateTime.Now.Ticks);
                do
                {
                    x = rand.Next(0, player.Owner.Map.Width);
                    y = rand.Next(0, player.Owner.Map.Height);
                } while (player.Owner.Map[x, y].Region != TileRegion.Spawn);
                pet.Move(x + 0.5f, y + 0.5f);
                db.CreatePet(player.Client.Account, item);
                player.Owner.EnterWorld(pet);
                player.Client.SendPacket(new HatchPetMessagePacket
                {
                    PetName = skin.DisplayId,
                    PetSkin = skin.ObjectType
                });
                player.Client.SendPacket(new UpdatePacket
                {
                    Tiles      = new UpdatePacket.TileData[0],
                    NewObjects = new ObjectDef[1] {
                        pet.ToDefinition()
                    },
                    RemovedObjectIds = new int[0]
                });
            });
        }
 public void EvolveResult(int level, int rarity, ref PetStruct newPetStruct)
 {
     FuseResult(level, rarity);
     PetStruct s = GetPetStruct(Manager, PetFamily, (Rarity)rarity);
     this.Skin = Manager.GameData.IdToPetSkin[s.DefaultSkin].DisplayId;
     this.SkinId = Manager.GameData.IdToPetSkin[s.DefaultSkin].ObjectType;
     newPetStruct = s;
 }
        private static List<AbilityItem> GetPetAbilites(Item egg, PetStruct petStruct)
        {
            List<Ability> abilities = new List<Ability>()
            {
                Ability.AttackClose,
                Ability.AttackFar,
                Ability.AttackMid,
                Ability.Decoy,
                Ability.Electric,
                Ability.Heal,
                Ability.MagicHeal,
                Ability.RisingFury,
                Ability.Savage
            };

            Random rand = new Random((int)DateTime.Now.Ticks);
            List<AbilityItem> ret = new List<AbilityItem>(3);
            int power = 1;

            switch (egg.Rarity)
            {
                case Rarity.Uncommon:
                    power = 30;
                    break;

                case Rarity.Rare:
                    power = 50;
                    break;

                case Rarity.Legendary:
                    power = 70;
                    break;
            }

            for (int i = 0; i < 3; i++)
            {
                if (i == 0 && petStruct.FirstAbility != null)
                {
                    ret.Add(new AbilityItem
                    {
                        Power = power,
                        Points = 0,
                        Type = (int)petStruct.FirstAbility
                    });

                    abilities.Remove((Ability)petStruct.FirstAbility);
                }
                else
                {
                    Ability ability = abilities[rand.Next(abilities.Count)];
                    ret.Add(new AbilityItem
                    {
                        Power = power,
                        Points = 0,
                        Type = (int)ability
                    });

                    if (ability == Ability.AttackClose || ability == Ability.AttackFar || ability == Ability.AttackMid)
                    {
                        abilities.Remove(Ability.AttackClose);
                        abilities.Remove(Ability.AttackFar);
                        abilities.Remove(Ability.AttackMid);
                    }
                    else
                        abilities.Remove(ability);
                }
            }

            return ret;
        }
Example #11
0
        public void AddObjects(XElement root)
        {
            foreach (XElement elem in root.XPathSelectElements("//Object"))
            {
                if (elem.Element("Class") == null)
                {
                    continue;
                }
                string cls = elem.Element("Class").Value;
                string id  = elem.Attribute("id").Value;

                ushort     type;
                XAttribute typeAttr = elem.Attribute("type");
                if (typeAttr == null)
                {
                    continue;
                }
                type = (ushort)Utils.FromString(typeAttr.Value);

                if (cls == "PetBehavior" || cls == "PetAbility")
                {
                    continue;
                }

                if (type2id_obj.ContainsKey(type))
                {
                    log.WarnFormat("'{0}' and '{1}' has the same ID of 0x{2:x4}!", id, type2id_obj[type], type);
                }
                if (id2type_obj.ContainsKey(id))
                {
                    log.WarnFormat("0x{0:x4} and 0x{1:x4} has the same name of {2}!", type, id2type_obj[id], id);
                }

                type2id_obj[type]   = id;
                id2type_obj[id]     = type;
                type2elem_obj[type] = elem;

                switch (cls)
                {
                case "Equipment":
                case "Dye":
                    items[type] = new Item((short)type, elem);
                    break;

                case "Portal":
                case "GuildHallPortal":
                    try
                    {
                        portals[type] = new PortalDesc(type, elem);
                    }
                    catch
                    {
                        log.Error("Error for portal: " + type + " id: " + id);
                    }
                    break;

                case "Pet":
                    type2pet[type] = new PetStruct(type, elem);
                    break;

                case "PetSkin":
                    id2pet_skin[id] = new PetSkin(type, elem);
                    break;

                case "PetBehavior":
                case "PetAbility":
                    break;

                default:
                    objDescs[type] = new ObjectDesc(type, elem);
                    break;
                }
            }
        }
Example #12
0
        public void AddObjects(XElement root)
        {
            foreach (XElement elem in root.XPathSelectElements("//Object"))
            {
                if (elem.Element("Class") == null)
                {
                    continue;
                }
                string cls = elem.Element("Class").Value;
                string id  = elem.Attribute("id").Value;

                ushort     type;
                XAttribute typeAttr = elem.Attribute("type");
                if (typeAttr == null)
                {
                    type = (ushort)assign.Assign(id, elem);
                }
                else
                {
                    type = (ushort)Utils.FromString(typeAttr.Value);
                }

                if (cls == "PetBehavior" || cls == "PetAbility")
                {
                    continue;
                }

                if (type2id_obj.ContainsKey(type))
                {
                    log.WarnFormat("'{0}' and '{1}' has the same ID of 0x{2:x4}!", id, type2id_obj[type], type);
                }
                if (id2type_obj.ContainsKey(id))
                {
                    log.WarnFormat("0x{0:x4} and 0x{1:x4} has the same name of {2}!", type, id2type_obj[id], id);
                }

                type2id_obj[type]   = id;
                id2type_obj[id]     = type;
                type2elem_obj[type] = elem;

                switch (cls)
                {
                case "Equipment":
                case "Dye":
                    items[type] = new Item(type, elem);
                    break;

                case "Portal":
                case "GuildHallPortal":
                    try
                    {
                        portals[type] = new PortalDesc(type, elem);
                    }
                    catch
                    {
                        Console.WriteLine("Error for portal: " + type + " id: " + id);

                        /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?*
                         *  Tomb Portal of Cowardice,  Dungeon Portal,  Portal of Cowardice,  Realm Portal,  Glowing Portal of Cowardice,  Glowing Realm Portal,  Nexus Portal,  Locked Wine Cellar Portal*/
                    }
                    break;

                case "Pet":
                    type2pet[type] = new PetStruct(type, elem);
                    break;

                case "PetSkin":
                    id2pet_skin[id] = new PetSkin(type, elem);
                    break;

                case "PetBehavior":
                case "PetAbility":
                    break;

                default:
                    objDescs[type] = new ObjectDesc(type, elem);
                    break;
                }

                XAttribute extAttr = elem.Attribute("ext");
                bool       ext;
                if (extAttr != null && bool.TryParse(extAttr.Value, out ext) && ext)
                {
                    if (elem.Attribute("type") == null)
                    {
                        elem.Add(new XAttribute("type", type));
                    }
                    addition.Add(elem);
                    updateCount++;
                }
            }
        }
        public void AddObjects(XElement root)
        {
            foreach (XElement elem in root.XPathSelectElements("//Object"))
            {
                if (elem.Element("Class") == null) continue;
                string cls = elem.Element("Class").Value;
                string id = elem.Attribute("id").Value;

                ushort type;
                XAttribute typeAttr = elem.Attribute("type");
                if (typeAttr == null)
                    type = (ushort)assign.Assign(id, elem);
                else
                    type = (ushort)Utils.FromString(typeAttr.Value);

                if (cls == "PetBehavior" || cls == "PetAbility") continue;

                if (type2id_obj.ContainsKey(type))
                    log.WarnFormat("'{0}' and '{1}' has the same ID of 0x{2:x4}!", id, type2id_obj[type], type);
                if (id2type_obj.ContainsKey(id))
                    log.WarnFormat("0x{0:x4} and 0x{1:x4} has the same name of {2}!", type, id2type_obj[id], id);

                type2id_obj[type] = id;
                id2type_obj[id] = type;
                type2elem_obj[type] = elem;

                switch (cls)
                {
                    case "Equipment":
                    case "Dye":
                        items[type] = new Item(type, elem);
                        break;
                    case "Portal":
                    case "GuildHallPortal":
                        try
                        {
                            portals[type] = new PortalDesc(type, elem);
                        }
                        catch
                        {
                            Console.WriteLine("Error for portal: " + type + " id: " + id);
                            /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?*
            *  Tomb Portal of Cowardice,  Dungeon Portal,  Portal of Cowardice,  Realm Portal,  Glowing Portal of Cowardice,  Glowing Realm Portal,  Nexus Portal,  Locked Wine Cellar Portal*/
                        }
                        break;
                    case "Pet":
                        type2pet[type] = new PetStruct(type, elem);
                        break;
                    case "PetSkin":
                        id2pet_skin[id] = new PetSkin(type, elem);
                        break;
                    case "PetBehavior":
                    case "PetAbility":
                        break;
                    default:
                        objDescs[type] = new ObjectDesc(type, elem);
                        break;
                }

                XAttribute extAttr = elem.Attribute("ext");
                bool ext;
                if (extAttr != null && bool.TryParse(extAttr.Value, out ext) && ext)
                {
                    if (elem.Attribute("type") == null)
                        elem.Add(new XAttribute("type", type));
                    addition.Add(elem);
                    updateCount++;
                }
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            PetStruct dog = new PetStruct();

            dog.type   = PetType.dog;
            dog.hasFur = true;
            dog.name   = "Anthony";
            dog.legs   = 4;

            PetClass duck = new PetClass();

            duck.type   = PetType.duck;
            duck.hasFur = true;
            duck.name   = "Donald";
            duck.legs   = 2;

            Console.WriteLine("the dog name {0} has {1} and is {2} type", dog.name, dog.legs, dog.type);
            Console.WriteLine("the duck name {0} has {1} and is {2} type", duck.name, duck.legs, duck.type);
            MultipliedLeg(dog, duck);
            Console.WriteLine("the dog name {0} has {1} and is {2} type", dog.name, dog.legs, dog.type);
            Console.WriteLine("the duck name {0} has {1} and is {2} type", duck.name, duck.legs, duck.type);

            //initialize without pre-populated array.
            int[]    intArray    = new int[5];
            string[] stringArray = new string[3];

            //initalize prepopulated array.
            int[]    populatedIntArray    = new int[] { 1, 2, 3, 4, 5 };
            string[] populatedStringArray = new string[] { "Binh", "Hai, 'Anthony" };

            //asign value can be done for both unpopulated and prepopulated array
            intArray[0] = 2;
            Console.WriteLine(intArray[0]);

            populatedStringArray[1] = "Bento";
            Console.WriteLine(populatedStringArray[1]);

            //********MULTIDIMENTIONAL ARRAY***********
            int[,] multiInt          = new int[3, 5];
            int[,] multiPopulatedInt = { { 1, 2, 3 }, { 3, 4, 5 }, { 6, 7, 8 } };

            int val1 = multiPopulatedInt[0, 0]; //val is 1
            int val2 = multiPopulatedInt[1, 2]; //val is 5
            int val3 = multiPopulatedInt[2, 1]; //val is 7

            Console.WriteLine(val1);
            Console.WriteLine(val2);
            Console.WriteLine(val3);


            //*********LIST************
            //initilize List, not length asigned needed
            List <string> listOfStrings = new List <string>();

            //add or remove item to the list
            listOfStrings.Add("First Item");
            listOfStrings.Add("Second Item");
            listOfStrings.Add("Third Item");
            listOfStrings.Insert(1, "inserted Item"); //insert by index will push the value down instead of overide it

            listOfStrings.Remove("First Item");       //remove particular Item
            listOfStrings.RemoveAt(0);                //remove index

            Console.WriteLine(listOfStrings.Count);
            Console.WriteLine(listOfStrings[1]);

            //***********DICTIONARY****************
            Dictionary <string, string> selectedActor = new Dictionary <string, string>();

            selectedActor.Add("name", "Jame Bond");
            selectedActor.Add("nationality", "England");
            selectedActor.Add("job", "MI6-SPY");
            selectedActor.Add("status", "Single");

            Console.WriteLine(selectedActor["name"]);
            Console.WriteLine(selectedActor["nationality"]);
            Console.WriteLine(selectedActor["job"]);
            Console.WriteLine(selectedActor["status"]);


            //************LINQ********************
            List <PetClass> petList = new List <PetClass>();

            petList.Add(new PetClass {
                name = "Anthony", type = PetType.dog, legs = 4, hasFur = true
            });
            petList.Add(new PetClass {
                name = "Dante", type = PetType.duck, legs = 2, hasFur = false
            });

            //List<PetClass> selectedPet = (from p in petList
            //                            where p.legs == 4
            //                          select p).ToList();
            List <PetClass> selectedPet = petList.Where(p => p.legs == 4).ToList();

            //PetClass selectedPet1 = (from p in petList
            //                          where p.hasFur == false
            //                        select p).FirstOrDefault();
            PetClass selectedPet1 = petList.Where(p => p.hasFur == false).FirstOrDefault();


            Console.WriteLine("result of the selectedPet is " + selectedPet[0].type + " and the name is " + selectedPet[0].name);
            Console.WriteLine("result of the selectedPet is " + selectedPet1.type + " and the name is " + selectedPet1.name);
        }