public bool OnCast(Character caster, string args)
        {
            #region Determine number of pets. Return false if at or above MAX_PETS.
            if (!caster.IsImmortal)
            {
                int petCount = 0;

                foreach (NPC pet in caster.Pets)
                {
                    if (pet.QuestList.Count == 0)
                    {
                        petCount++;
                    }
                }

                if (petCount >= GameSpell.MAX_PETS)
                {
                    caster.WriteToDisplay("You do not possess the mental fortitude to summon an ally.");
                    return(false);
                }
            }
            #endregion

            args = args.Replace(ReferenceSpell.Command, "");
            args = args.Trim();
            string[] sArgs = args.Split(" ".ToCharArray());

            #region Determine Power
            int magicSkillLevel = Skills.GetSkillLevel(caster.magic);
            int power           = magicSkillLevel;

            if (sArgs.Length > 0)
            {
                try
                {
                    power = Convert.ToInt32(sArgs[0]);

                    if (power > magicSkillLevel && !caster.IsImmortal)
                    {
                        power = magicSkillLevel;
                    }
                }
                catch (Exception)
                {
                    power = magicSkillLevel;
                }
            }

            // Rangers get the spell at skill level 3, acts as skill level 1.
            if (!caster.IsImmortal && caster.BaseProfession != Character.ClassType.Druid)
            {
                power = power - 3;
            }

            if (power < 1)
            {
                power = 1;
            }
            #endregion

            List <Entity> availableEntities = new List <Entity>();

            foreach (Tuple <int, Entity, bool> tuple in AlliesAvailable)
            {
                if (tuple.Item1 > power)
                {
                    break;                      // Allies are in sequential power order.
                }
                if (tuple.Item1 <= power)
                {
                    // Not all allies can be summoned indoors.
                    if (caster.CurrentCell.IsOutdoors || (!caster.CurrentCell.IsOutdoors && !tuple.Item3))
                    {
                        availableEntities.Add(tuple.Item2);
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            if (availableEntities.Count <= 0)
            {
                return(false);
            }

            Entity entity = availableEntities[Rules.Dice.Next(0, availableEntities.Count - 1)];

            Autonomy.EntityBuilding.EntityBuilder builder = new Autonomy.EntityBuilding.EntityBuilder();

            string profession = "fighter";

            // If human or humanoid, possibly switch to another profession besides fighter.
            if (Autonomy.EntityBuilding.EntityLists.IsHumanOrHumanoid(entity))
            {
                Character.ClassType[] availableProfessions = new Character.ClassType[] { Character.ClassType.Fighter, Character.ClassType.Thaumaturge, Character.ClassType.Wizard };

                Character.ClassType randomProfession = availableProfessions[Rules.Dice.Next(0, availableProfessions.Length - 1)];

                switch (randomProfession)
                {
                case Character.ClassType.Fighter:
                    profession = Autonomy.EntityBuilding.EntityBuilder.FIGHTER_SYNONYMS[Rules.Dice.Next(0, Autonomy.EntityBuilding.EntityBuilder.FIGHTER_SYNONYMS.Length - 1)];
                    break;

                case Character.ClassType.Thaumaturge:
                    profession = Autonomy.EntityBuilding.EntityBuilder.THAUMATURGE_SYNONYMS[Rules.Dice.Next(0, Autonomy.EntityBuilding.EntityBuilder.THAUMATURGE_SYNONYMS.Length - 1)];
                    break;

                case Character.ClassType.Wizard:
                    profession = Autonomy.EntityBuilding.EntityBuilder.WIZARD_SYNONYMS[Rules.Dice.Next(0, Autonomy.EntityBuilding.EntityBuilder.WIZARD_SYNONYMS.Length - 1)];
                    break;
                }
            }

            NPC ally = builder.BuildEntity("nature allied", entity, caster.Map.ZPlanes[caster.Z], profession);

            // Set level.
            ally.Level = Math.Max(caster.Level, magicSkillLevel) + Rules.Dice.Next(-1, 1); // magic skill should be set to higher skill if using impcast
            if (ally.Level <= 0)
            {
                ally.Level = 1;
            }

            builder.SetOnTheFlyVariables(ally);
            ally.Alignment = caster.Alignment;
            builder.SetName(ally, ally.BaseProfession.ToString());
            builder.SetDescriptions("", ally, caster.Map.ZPlanes[caster.Z], ally.BaseProfession.ToString().ToLower());
            Autonomy.EntityBuilding.EntityBuilder.SetGender(ally, caster.Map.ZPlanes[caster.Z]);
            Autonomy.EntityBuilding.EntityBuilder.SetVisualKey(ally.entity, ally);
            if (ally.spellDictionary.Count > 0)
            {
                ally.magic = Skills.GetSkillForLevel(ally.Level + Rules.Dice.Next(-1, 1));
            }
            GameSpell.FillSpellLists(ally);

            if (Autonomy.EntityBuilding.EntityLists.IsHumanOrHumanoid(ally))
            {
                List <int> armorToWear;

                if (power <= 13)
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_STUDDED_LEATHER].GetArmorList(ally);
                }
                else if (power < 16)
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_CHAINMAIL].GetArmorList(ally);
                }
                else
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_BANDED_MAIL].GetArmorList(ally);
                }

                foreach (int id in armorToWear)
                {
                    Item armor = Item.CopyItemFromDictionary(id);
                    // It's basic armor sets only. Label them as ethereal. (They will go back with the phantasm to their home plane. Given items drop.)
                    armor.special += " " + Item.EXTRAPLANAR;
                    ally.WearItem(armor);
                }
            }

            if (Autonomy.EntityBuilding.EntityLists.IsHumanOrHumanoid(ally) || Autonomy.EntityBuilding.EntityLists.ANIMALS_WIELDING_WEAPONS.Contains(ally.entity))
            {
                List <int> weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(ally, true);
                if (weaponsList.Count > 0)
                {
                    ally.EquipRightHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }
                weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(ally, false);
                if (weaponsList.Count > 0)
                {
                    ally.EquipLeftHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }

                if (ally.RightHand != null)
                {
                    ally.RightHand.special += " " + Item.EXTRAPLANAR;
                }
                if (ally.LeftHand != null)
                {
                    ally.LeftHand.special += " " + Item.EXTRAPLANAR;
                }
            }

            ally.Hits    = ally.HitsFull;
            ally.Mana    = ally.ManaFull;
            ally.Stamina = ally.StaminaFull;

            ally.Age     = GameWorld.World.AgeCycles[Rules.Dice.Next(0, GameWorld.World.AgeCycles.Count - 1)];
            ally.special = "despawn summonnaturesally";

            int twoMinutes = Utils.TimeSpanToRounds(new TimeSpan(0, 2, 0));
            // 18 minutes + 2 minutes for every skill level past 3
            ally.RoundsRemaining = (twoMinutes * 9) + ((magicSkillLevel - ReferenceSpell.RequiredLevel) * twoMinutes);
            //ally.species = Globals.eSpecies.Magical; // this may need to be changed for AI to work properly

            ally.canCommand = true;
            ally.IsMobile   = true;
            ally.IsSummoned = true;
            ally.IsUndead   = false;

            ally.FollowID = caster.UniqueID;

            ally.PetOwner = caster;
            caster.Pets.Add(ally);

            if (ally.CurrentCell != caster.CurrentCell)
            {
                ally.CurrentCell = caster.CurrentCell;
            }

            ReferenceSpell.SendGenericCastMessage(caster, null, true);

            ally.EmitSound(ally.idleSound);
            caster.WriteToDisplay((ally.longDesc.StartsWith("evil") ? "An " : "A ") + ally.longDesc + " answers your call for assistance.");
            ally.AddToWorld();
            return(true);
        }
Esempio n. 2
0
        public bool OnCast(Character caster, string args)
        {
            /*      Power   Mana    Type        Armor (item IDs)            Skill (base)    Spells
             *      1       20      phantasm    leather (8010, 15010)       7               none
             *      2       23      eidolon     chain (8015, 15015)         8               magic missile
             *      3       30      djinn       banded mail (8020, 15020)   9               ice storm
             *      4       32      salamander  sally scales (8102)         10              firewall
             *      5       35      efreet      steel (8021, 15021)         11              concussion
             *      6       40      marid       steel (8021, 15021)         12              icespear
             *      7       42      dao         steel (8021, 15021)         13              lightninglance
             */

            args = args.Replace(ReferenceSpell.Command, "");

            args = args.Trim();

            string[] sArgs = args.Split(" ".ToCharArray());

            #region Determine power.
            PhantasmPower power = PhantasmPower.Phantasm; // default power

            if (sArgs.Length > 0)
            {
                try
                {
                    power = (PhantasmPower)Convert.ToInt32(sArgs[0]);

                    if (power > PhantasmPower.Dao)
                    {
                        power = PhantasmPower.Dao;
                    }
                }
                catch (Exception)
                {
                    power = PhantasmPower.Phantasm;
                }
            }
            #endregion

            int magicSkillLevel = Skills.GetSkillLevel(caster.magic);
            if (caster.IsImmortal)
            {
                magicSkillLevel = 19;
            }

            #region Verify skill level for power of spell.
            if (!caster.IsImmortal)
            {
                if (magicSkillLevel < 19)
                {
                    if (magicSkillLevel < 19 && power == PhantasmPower.Dao)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon dao.");
                        return(true);
                    }

                    if (magicSkillLevel < 18 && power == PhantasmPower.Marid)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon marid.");
                        return(true);
                    }

                    if (magicSkillLevel < 17 && power == PhantasmPower.Efreet)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon efreeti.");
                        return(true);
                    }

                    if (magicSkillLevel < 15 && power == PhantasmPower.Salamander)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon salamanders.");
                        return(true);
                    }

                    if (magicSkillLevel < 13 && power == PhantasmPower.Djinn)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon djinn.");
                        return(true);
                    }

                    if (magicSkillLevel < 12 && power == PhantasmPower.Eidolon)
                    {
                        caster.WriteToDisplay("You are not skilled enough yet to summon eidolon.");
                        return(true);
                    }
                }
            }
            #endregion

            #region Determine number of pets. Return false if at or above MAX_PETS.
            int petCount = 0;

            foreach (NPC pet in caster.Pets)
            {
                if (pet.QuestList.Count == 0)
                {
                    petCount++;
                }
            }

            // TODO: item or skill/talent to summon more pets
            if (!caster.IsImmortal && petCount >= GameSpell.MAX_PETS)
            {
                caster.WriteToDisplay("You do not possess the mental fortitude to control another pet.");
                return(false);
            }
            #endregion

            #region Setup the summoned spirit.
            int        npcID       = 902;
            List <int> armorToWear = new List <int>();

            Autonomy.EntityBuilding.EntityLists.Entity entity = Autonomy.EntityBuilding.EntityLists.Entity.None;

            switch (power)
            {
            case PhantasmPower.Phantasm:     // phantasm with leather
                if (caster.Mana < ReferenceSpell.ManaCost)
                {
                    return(false);
                }
                entity = Autonomy.EntityBuilding.EntityLists.Entity.Phantasm;
                break;

            case PhantasmPower.Eidolon:     // eidolon with chain
                if (caster.Mana < ReferenceSpell.ManaCost + 3)
                {
                    caster.Mana -= 3;
                    return(false);
                }
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Eidolon;
                caster.Mana -= 5;
                break;

            case PhantasmPower.Djinn:     // djinn with banded mail
                if (caster.Mana < ReferenceSpell.ManaCost + 10)
                {
                    caster.Mana -= 10;
                    return(false);
                }
                caster.Mana -= 10;
                npcID        = 903; // djinn with banded mail and icestorm
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Djinn;
                break;

            case PhantasmPower.Salamander:     // salamander
                if (caster.Mana < ReferenceSpell.ManaCost + 12)
                {
                    caster.Mana -= 12;
                    return(false);
                }
                caster.Mana -= 12;
                npcID        = 37; // salamander with scales and firewall
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Salamander;
                break;

            case PhantasmPower.Efreet:     // efreet with plate
                if (caster.Mana < ReferenceSpell.ManaCost + 15)
                {
                    caster.Mana -= 15;
                    return(false);
                }
                caster.Mana -= 15;
                npcID        = 904; // efreet with steel plate and concussion
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Efreet;
                break;

            case PhantasmPower.Marid:     // efreet with plate
                if (caster.Mana < ReferenceSpell.ManaCost + 20)
                {
                    caster.Mana -= 20;
                    return(false);
                }
                caster.Mana -= 20;
                npcID        = 904; // marid with steel plate and icespear
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Marid;
                break;

            case PhantasmPower.Dao:     // efreet with plate
                if (caster.Mana < ReferenceSpell.ManaCost + 23)
                {
                    caster.Mana -= 23;
                    return(false);
                }
                caster.Mana -= 23;
                npcID        = 904; // dao with steel plate and lightninglance
                entity       = Autonomy.EntityBuilding.EntityLists.Entity.Dao;
                break;

            default:
                break;
            }

            // Create the summoned spirit.
            NPC phantasm = NPC.LoadNPC(npcID, caster.FacetID, caster.LandID, caster.MapID, caster.X, caster.Y, caster.Z, -1);

            foreach (Item wornItem in new List <Item>(phantasm.wearing))
            {
                phantasm.RemoveWornItem(wornItem);
            }

            phantasm.wearing.Clear();

            Autonomy.EntityBuilding.EntityBuilder builder = new Autonomy.EntityBuilding.EntityBuilder();

            phantasm.Level = caster.Level + (int)power;

            phantasm.entity = entity;
            builder.SetOnTheFlyVariables(phantasm);
            builder.SetName(phantasm, phantasm.BaseProfession.ToString());
            builder.SetDescriptions("", phantasm, caster.Map.ZPlanes[caster.Z], phantasm.BaseProfession.ToString().ToLower());
            Autonomy.EntityBuilding.EntityBuilder.SetVisualKey(phantasm.entity, phantasm);

            /*      Power   Mana    Type        Armor (item IDs)            Skill (base)    Spells
             *      1       20      phantasm    leather (8010, 15010)       7               none
             *      2       23      eidolon     chain (8015, 15015)         8               magic missile
             *      3       30      djinn       banded mail (8020, 15020)   9               ice storm
             *      4       32      salamander  sally scales (8102)         10              firewall
             *      5       35      efreet      steel (8021, 15021)         11              concussion
             *      6       40      marid       steel (8021, 15021)         12              icespear
             *      7       43      dao         steel (8021, 15021)         13              lightninglance
             */

            // basic phantasm
            if (power <= PhantasmPower.Phantasm)
            {
                phantasm.HitsMax += (int)power * 100;
                phantasm.ManaMax  = 0;
                phantasm.castMode = NPC.CastMode.Never;
                phantasm.magic    = 0;
            }
            else
            {
                phantasm.ManaMax  = (int)power * (3 + Rules.RollD(1, 6));
                phantasm.castMode = NPC.CastMode.NoPrep;
                phantasm.magic    = Skills.GetSkillForLevel(((int)power * 2) + Rules.RollD(1, 3));
                phantasm.spellDictionary.Clear();

                switch (power)
                {
                case PhantasmPower.Eidolon:     // eidolon with magic missile
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Magic_Missile))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Magic_Missile, GameSpell.GenerateMagicWords());
                    }
                    break;

                case PhantasmPower.Djinn:     // djinn with icestorm
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Icestorm))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Icestorm, GameSpell.GenerateMagicWords());
                    }
                    // talents
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DualWield.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DualWield).Command, DateTime.UtcNow);
                    }
                    break;

                case PhantasmPower.Salamander:     // salamander with firewall and firebolt
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Firewall))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Firewall, GameSpell.GenerateMagicWords());
                    }
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Firebolt))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Firebolt, GameSpell.GenerateMagicWords());
                    }
                    // talent
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DoubleAttack.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DoubleAttack).Command, DateTime.UtcNow);
                    }
                    break;

                case PhantasmPower.Efreet:     // efreet with concussion
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Concussion))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Concussion, GameSpell.GenerateMagicWords());
                    }
                    // talents
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DualWield.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DualWield).Command, DateTime.UtcNow);
                    }
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DoubleAttack.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DoubleAttack).Command, DateTime.UtcNow);
                    }
                    break;

                case PhantasmPower.Marid:
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Icespear))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Icespear, GameSpell.GenerateMagicWords());
                    }
                    // talents
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DualWield.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DualWield).Command, DateTime.UtcNow);
                    }
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DoubleAttack.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DoubleAttack).Command, DateTime.UtcNow);
                    }
                    break;

                case PhantasmPower.Dao:
                    // lightning lance
                    if (!phantasm.spellDictionary.ContainsKey((int)GameSpell.GameSpellID.Lightning_Lance))
                    {
                        phantasm.spellDictionary.Add((int)GameSpell.GameSpellID.Lightning_Lance, GameSpell.GenerateMagicWords());
                    }
                    // talents (dual wield, double attack, riposte)
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DualWield.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DualWield).Command, DateTime.UtcNow);
                    }
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.DoubleAttack.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.DoubleAttack).Command, DateTime.UtcNow);
                    }
                    if (!phantasm.talentsDictionary.ContainsKey(Talents.GameTalent.TALENTS.Riposte.ToString().ToLower()))
                    {
                        phantasm.talentsDictionary.Add(Talents.GameTalent.GetTalent(Talents.GameTalent.TALENTS.Riposte).Command, DateTime.UtcNow);
                    }
                    break;

                default:
                    phantasm.spellDictionary.Clear();
                    break;
                }
            }

            // Armor sets.

            switch (power)
            {
            case PhantasmPower.Phantasm:     // phantasm with leather
                armorToWear = ArmorSet.ArmorSetDictionary[ArmorSet.BASIC_LEATHER].GetArmorList(phantasm);
                break;

            case PhantasmPower.Eidolon:     // eidolon with chain
                armorToWear = ArmorSet.ArmorSetDictionary[ArmorSet.BASIC_CHAINMAIL].GetArmorList(phantasm);
                break;

            case PhantasmPower.Djinn:     // djinn with banded mail
                armorToWear = ArmorSet.ArmorSetDictionary[ArmorSet.BASIC_BANDED_MAIL].GetArmorList(phantasm);
                break;

            case PhantasmPower.Salamander:     // salamander
                armorToWear.Add(Item.ID_FIRE_SALAMANDER_SCALE_VEST);
                break;

            case PhantasmPower.Efreet:     // efreet with plate
            case PhantasmPower.Marid:
            case PhantasmPower.Dao:
                armorToWear = ArmorSet.ArmorSetDictionary[ArmorSet.BASIC_STEEL].GetArmorList(phantasm);
                break;

            default:
                break;
            }

            // Wear armor.
            foreach (int id in armorToWear)
            {
                Item armor = Item.CopyItemFromDictionary(id);
                // It's basic armor sets only. Label them as ethereal. (They will go back with the phantasm to their home plane. Given items drop.)
                armor.special += " " + Item.EXTRAPLANAR;
                phantasm.WearItem(armor);
            }

            if (phantasm.RightHand != null)
            {
                phantasm.RightHand.special += " " + Item.EXTRAPLANAR;
            }
            if (phantasm.LeftHand != null)
            {
                phantasm.LeftHand.special += " " + Item.EXTRAPLANAR;
            }

            GameSpell.FillSpellLists(phantasm);

            phantasm.Hits    = phantasm.HitsFull;
            phantasm.Mana    = phantasm.ManaFull;
            phantasm.Stamina = phantasm.StaminaFull;

            //phantasm.Alignment = (Globals.eAlignment)Enum.Parse(typeof(Globals.eAlignment), caster.Alignment.ToString());
            phantasm.Alignment = caster.Alignment;
            phantasm.Age       = 0;
            phantasm.special   = "despawn";

            int fiveMinutes = Utils.TimeSpanToRounds(new TimeSpan(0, 5, 0));
            // 30 minutes + 5 minutes for every skill level past 11 minus 5 minutes for every power of the spell beyond 1.
            phantasm.RoundsRemaining = (fiveMinutes * 6) + ((magicSkillLevel - ReferenceSpell.RequiredLevel) * fiveMinutes) - (((int)power - 1) * fiveMinutes);
            phantasm.species         = Globals.eSpecies.Magical; // this may need to be changed for AI to work properly

            phantasm.canCommand = true;
            phantasm.IsMobile   = true;
            phantasm.IsSummoned = true;
            phantasm.IsUndead   = false;

            phantasm.FollowID = caster.UniqueID;

            phantasm.PetOwner = caster;
            caster.Pets.Add(phantasm);
            #endregion

            if (phantasm.CurrentCell != caster.CurrentCell)
            {
                phantasm.CurrentCell = caster.CurrentCell;
            }

            phantasm.EmitSound(phantasm.idleSound);

            phantasm.AddToWorld();

            return(true);
        }
Esempio n. 3
0
        public bool OnCast(Character caster, string args)
        {
            // There is no power level to this spell. Only one demon may be controlled, and if the caster has
            // any pets the spell will flail. The demon will be very powerful, this it's why it is a skill 17 spell.

            // First gather a list of unnamed demons.

            if (caster.Pets != null && caster.Pets.Count > 0 && (caster is PC) && (caster as PC).ImpLevel < Globals.eImpLevel.DEVJR)
            {
                caster.WriteToDisplay("Summoning a demon requires your full concentration.");
                return(false);
            }

            List <EntityLists.Entity> availableDemons = new List <EntityLists.Entity>();

            foreach (EntityLists.Entity entity in EntityLists.DEMONS)
            {
                if (!EntityLists.NAMED_DEMONS.Contains(entity))
                {
                    availableDemons.Add(entity);
                }
            }

            NPC demon = NPC.LoadNPC(Item.ID_SUMMONEDMOB, caster.FacetID, caster.LandID, caster.MapID, caster.X, caster.Y, caster.Z, -1);

            EntityLists.Entity chosenDemon = availableDemons[Rules.Dice.Next(availableDemons.Count)];

            EntityBuilder builder = new EntityBuilder();

            demon.Level  = caster.Level + Rules.RollD(3, 4);
            demon.entity = chosenDemon;
            List <Character.ClassType> allowedProfessions = new List <Character.ClassType>
            {
                Character.ClassType.Fighter,
                Character.ClassType.Ravager,
                //Character.ClassType.Sorcerer,
                //Character.ClassType.Thaumaturge,
                Character.ClassType.Thief,
                Character.ClassType.Wizard,
            };

            demon.BaseProfession = allowedProfessions[Rules.Dice.Next(0, allowedProfessions.Count - 1)];

            builder.SetOnTheFlyVariables(demon);
            EntityBuilder.SetVisualKey(demon.entity, demon);
            builder.SetName(demon, demon.BaseProfession.ToString().ToLower());
            builder.SetDescriptions("summoned", demon, caster.Map.ZPlanes[caster.Z], demon.BaseProfession.ToString().ToLower());
            EntityBuilder.SetGender(demon, caster.Map.ZPlanes[caster.Z]);
            EntityBuilder.SetVisualKey(demon.entity, demon);

            if (demon.IsSpellUser)
            {
                NPC.CreateGenericSpellList(demon);
                GameSpell.FillSpellLists(demon);
            }

            if (EntityLists.IsHumanOrHumanoid(demon))
            {
                demon.wearing.Clear();

                List <int> armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_STEEL].GetArmorList(demon);

                foreach (int id in armorToWear)
                {
                    Item armor = Item.CopyItemFromDictionary(id);
                    armor.special += " " + Item.EXTRAPLANAR;
                    demon.WearItem(armor);
                }
            }

            if (EntityLists.IsHumanOrHumanoid(demon) || EntityLists.ANIMALS_WIELDING_WEAPONS.Contains(demon.entity))
            {
                List <int> weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(demon, true);
                if (weaponsList.Count > 0)
                {
                    demon.EquipRightHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }
                weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(demon, false);
                if (weaponsList.Count > 0)
                {
                    demon.EquipLeftHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }

                if (demon.RightHand != null)
                {
                    demon.RightHand.special += " " + Item.EXTRAPLANAR;
                }
                if (demon.LeftHand != null)
                {
                    demon.LeftHand.special += " " + Item.EXTRAPLANAR;
                }
            }

            demon.castMode = NPC.CastMode.Limited;

            demon.Hits    = demon.HitsFull;
            demon.Mana    = demon.ManaFull;
            demon.Stamina = demon.StaminaFull;

            demon.Alignment = Globals.eAlignment.ChaoticEvil;
            demon.race      = "Hell";

            //demon.aiType = NPC.AIType.EmptySlot;
            demon.Age     = 0;
            demon.special = "despawn";
            int fiveMinutes = Utils.TimeSpanToRounds(new TimeSpan(0, 5, 0));

            // 5 minutes plus 1 minute per magic skill level
            demon.RoundsRemaining = fiveMinutes + Skills.GetSkillLevel(caster.magic) * Utils.TimeSpanToRounds(new TimeSpan(0, 1, 0));
            demon.species         = Globals.eSpecies.Demon; // this may need to be changed for AI to work properly
            demon.Alignment       = caster.Alignment;
            demon.canCommand      = true;
            demon.IsMobile        = true;
            demon.IsSummoned      = true;
            demon.IsUndead        = EntityLists.UNDEAD.Contains(demon.entity);

            demon.FollowID = caster.UniqueID;

            demon.PetOwner = caster;
            caster.Pets.Add(demon);

            if (demon.CurrentCell != caster.CurrentCell)
            {
                demon.CurrentCell = caster.CurrentCell;
            }

            demon.EmitSound(demon.idleSound);

            demon.AddToWorld();

            return(true);
        }
Esempio n. 4
0
        public bool OnCast(Character caster, string args)
        {
            #region Determine number of pets. Return false if at or above MAX_PETS.
            if (!caster.IsImmortal)
            {
                int petCount = 0;

                foreach (NPC pet in caster.Pets)
                {
                    if (pet.QuestList.Count == 0)
                    {
                        petCount++;
                    }
                }

                if (petCount >= GameSpell.MAX_PETS)
                {
                    caster.WriteToDisplay("You do not possess the mental fortitude to summon an ally.");
                    return(false);
                }
            }
            #endregion

            args = args.Replace(ReferenceSpell.Command, "");
            args = args.Trim();
            string[] sArgs = args.Split(" ".ToCharArray());

            #region Determine Power
            int magicSkillLevel = Skills.GetSkillLevel(caster.magic);
            int power           = magicSkillLevel;

            if (sArgs.Length > 0)
            {
                try
                {
                    power = Convert.ToInt32(sArgs[0]);

                    if (power > magicSkillLevel && !caster.IsImmortal)
                    {
                        power = magicSkillLevel;
                    }
                }
                catch (Exception)
                {
                    power = magicSkillLevel;
                }
            }

            if (power < 1)
            {
                power = caster.Level;
            }
            #endregion

            Entity entity = Entity.Fighter;

            Enum.TryParse(caster.BaseProfession.ToString(), true, out entity);

            EntityBuilder builder = new EntityBuilder();

            string profession = entity.ToString().ToLower();

            if (!EntityLists.IsHuman(caster) || Rules.RollD(1, 100) < 50)
            {
                string entityLowerCase = caster.entity.ToString().ToLower();
                if (entityLowerCase.StartsWith("drow"))
                {
                    entity = Entity.Drow;
                    // Drow.Master summons drow thieves, Drow.Matriarch summons drow priestesses unless uncomment below lines
                    //List<string> availableProfessions = new List<string>() {"anathema", "cleric", "ravager", "rogue", "sorcerer" };
                    //profession = availableProfessions[Rules.Dice.Next(0, availableProfessions.Count - 1)];
                }
                else if (EntityLists.ELVES.Contains(caster.entity))
                {
                    List <Entity> allyEntities = new List <Entity>()
                    {
                        Entity.Grey_Elf,
                        Entity.High_Elf,
                        Entity.Wood_Elf
                    };
                }
                else
                {
                    List <Entity> allyEntities = new List <Entity>()
                    {
                        Entity.Gnome, Entity.Goblin,
                        Entity.Kobold,
                        Entity.Orc,
                        Entity.Tengu,
                    };

                    entity = allyEntities[Rules.Dice.Next(0, allyEntities.Count - 1)];
                }

                //profession = EntityBuilder.THIEF_SYNONYMS[Rules.Dice.Next(0, EntityBuilder.THIEF_SYNONYMS.Length - 1)];
            }

            NPC ally = builder.BuildEntity("allied", entity, caster.Map.ZPlanes[caster.Z], profession);

            // Set level.
            ally.Level = Math.Max(caster.Level, magicSkillLevel) + Rules.Dice.Next(-1, 1); // magic skill should be set to higher skill if using impcast
            if (ally.Level <= 0)
            {
                ally.Level = 1;
            }

            builder.SetOnTheFlyVariables(ally);
            ally.Alignment = caster.Alignment;
            builder.SetName(ally, profession);
            builder.SetDescriptions("allied", ally, caster.Map.ZPlanes[caster.Z], ally.BaseProfession.ToString().ToLower());
            EntityBuilder.SetGender(ally, caster.Map.ZPlanes[caster.Z]);
            EntityBuilder.SetVisualKey(ally.entity, ally);
            if (ally.spellDictionary.Count > 0)
            {
                ally.magic = Skills.GetSkillForLevel(ally.Level + Rules.Dice.Next(-1, 1));
            }
            GameSpell.FillSpellLists(ally);

            if (EntityLists.IsHumanOrHumanoid(ally))
            {
                List <int> armorToWear;

                if (power <= 13)
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_STUDDED_LEATHER].GetArmorList(ally);
                }
                else if (power < 16)
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_CHAINMAIL].GetArmorList(ally);
                }
                else
                {
                    armorToWear = Autonomy.ItemBuilding.ArmorSets.ArmorSet.ArmorSetDictionary[Autonomy.ItemBuilding.ArmorSets.ArmorSet.FULL_BANDED_MAIL].GetArmorList(ally);
                }

                foreach (int id in armorToWear)
                {
                    Item armor = Item.CopyItemFromDictionary(id);
                    // It's basic armor sets only. Label them as ethereal. (They will go back with the phantasm to their home plane. Given items drop.)
                    armor.special += " " + Item.EXTRAPLANAR;
                    ally.WearItem(armor);
                }
            }

            if (EntityLists.IsHumanOrHumanoid(ally) || EntityLists.ANIMALS_WIELDING_WEAPONS.Contains(ally.entity))
            {
                List <int> weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(ally, true);
                if (weaponsList.Count > 0)
                {
                    ally.EquipRightHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }
                weaponsList = Autonomy.ItemBuilding.LootManager.GetBasicWeaponsFromArmory(ally, false);
                if (weaponsList.Count > 0)
                {
                    ally.EquipLeftHand(Item.CopyItemFromDictionary(weaponsList[Rules.Dice.Next(weaponsList.Count - 1)]));
                }

                if (ally.RightHand != null)
                {
                    ally.RightHand.special += " " + Item.EXTRAPLANAR;
                }
                if (ally.LeftHand != null)
                {
                    ally.LeftHand.special += " " + Item.EXTRAPLANAR;
                }
            }

            ally.Hits    = ally.HitsFull;
            ally.Mana    = ally.ManaFull;
            ally.Stamina = ally.StaminaFull;

            ally.Age     = GameWorld.World.AgeCycles[Rules.Dice.Next(0, GameWorld.World.AgeCycles.Count - 1)];
            ally.special = "despawn summonthief";

            int oneMinute = Utils.TimeSpanToRounds(new TimeSpan(0, 1, 0));
            // 10 minutes + 2 minutes for every skill level past 3
            ally.RoundsRemaining = (oneMinute * 5) + ((power - ReferenceSpell.RequiredLevel) * oneMinute);
            //ally.species = Globals.eSpecies.Magical; // this may need to be changed for AI to work properly

            ally.canCommand = true;
            ally.IsMobile   = true;
            ally.IsSummoned = true;
            ally.IsUndead   = false;

            ally.FollowID = caster.UniqueID;

            ally.PetOwner = caster;
            caster.Pets.Add(ally);

            if (ally.CurrentCell != caster.CurrentCell)
            {
                ally.CurrentCell = caster.CurrentCell;
            }

            ReferenceSpell.SendGenericCastMessage(caster, null, true);

            ally.EmitSound(ally.idleSound);
            caster.WriteToDisplay((ally.longDesc.StartsWith("evil") ? "An " : "A ") + ally.longDesc + " answers your call for assistance.");
            caster.SendToAllInSight(caster.GetNameForActionResult() + " summons an ally.");
            if (caster is NPC)
            {
                ally.MostHated = (caster as NPC).MostHated;
            }
            ally.AddToWorld();
            return(true);
        }