Example #1
0
        /// <summary>
        /// Read component
        /// </summary>
        /// <param name="reader">Reader instance</param>
        /// <returns>Entity component</returns>
        public static EntityComponent ReadComponent(this BinaryReader reader)
        {
            bool exists = reader.ReadBoolean();

            if (!exists)
            {
                return(null);
            }

            EntityComponent component = null;

            var componentType = (ComponentType)reader.ReadInt32();

            switch (componentType)
            {
            case ComponentType.Fighter:
                component = new Fighter(reader);
                break;

            case ComponentType.BasicMonster:
                component = new BasicMonster(reader);
                break;

            case ComponentType.ConfusedMonster:
                component = new ConfusedMonster(reader);
                break;

            case ComponentType.GolemMonster:
                component = new GolemMonster(reader);
                break;

            case ComponentType.SlimeMonster:
                component = new SlimeMonster(reader);
                break;

            case ComponentType.Inventory:
                component = new Inventory(reader);
                break;

            case ComponentType.Item:
                component = new Item(reader);
                break;

            case ComponentType.Stairs:
                component = new Stairs(reader);
                break;

            case ComponentType.Level:
                component = new Level(reader);
                break;

            case ComponentType.Equipment:
                component = new Equipment(reader);
                break;

            case ComponentType.Equippable:
                component = new Equippable(reader);
                break;

            case ComponentType.GroundTrigger:
                component = new GroundTrigger(reader);
                break;

            case ComponentType.MoveTrail:
                component = new MoveTrail(reader);
                break;

            default:
                throw new System.Exception("Unknown component type " + (int)componentType);
            }

            return(component);
        }
        /// <summary>
        /// Create a monster of the given type
        /// </summary>
        /// <param name="monsterType">Type</param>
        /// <param name="pos">Position</param>
        /// <returns>Monster entity</returns>
        public static EntityID CreateMonster(MonsterType monsterType, Vector2i pos)
        {
            EntityID monster = EntityID.empty;

            switch (monsterType)
            {
            case MonsterType.Rat:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.RAT,
                    new Color32(0xc0, 0x79, 0x58, 255),
                    C.FSTR.Set("Rat"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(20, 0, 4, 35);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Skeleton:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.SKELETON,
                    new Color32(0xdb, 0xd3, 0xc3, 255),
                    C.FSTR.Set("Skeletal Warrior"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(30, 2, 10, 100);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.ArcherSkeleton:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.SKELETON,
                    new Color32(0xdb, 0xd3, 0xc3, 255),
                    C.FSTR.Set("Skeletal Archer"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(30, 2, 5, 100);
                monster.e.ai        = new BasicMonster();
                monster.e.inventory = new Inventory(5);

                for (int i = 0; i < 4; i++)
                {
                    monster.e.inventory.AddItem(null, CreateItem(ItemType.Arrow, new Vector2i(-1, -1)));
                }

                var bow = CreateItem(ItemType.Bow, new Vector2i(-1, -1));
                monster.e.inventory.AddItem(null, bow);

                monster.e.equipment = new Equipment();
                monster.e.equipment.equipment[(int)EquipmentSlot.Ranged] = bow;

                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 0);         // Always prefer to shoot bow, unless no arrows
                ai.AddSkill(Skill.ShootBow, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Bat:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.BAT,
                    new Color32(0x7a, 0x44, 0x4a, 255),
                    C.FSTR.Set("Bat"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(15, 1, 3, 40);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Slime:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.SLIME,
                    new Color32(0x38, 0xd9, 0x73, 255),
                    C.FSTR.Set("Slime"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(30, 2, 5, 60);
                var ai = new SlimeMonster();
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.SlimeSmall:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.SLIME_SMALL,
                    new Color32(0x38, 0xd9, 0x73, 255),
                    C.FSTR.Set("Baby Slime"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(15, 0, 2, 30);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Ghost:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.GHOST,
                    new Color32(0xdb, 0xd3, 0xc3, 180),
                    C.FSTR.Set("Ghost"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(25, 3, 10, 80);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 75);
                ai.AddSkill(Skill.Teleport, 25);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Spider:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.SPIDER,
                    new Color32(0x5b, 0x5b, 0x7b, 255),
                    C.FSTR.Set("Spider"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(20, 2, 7, 50);
                var ai = new BasicMonster();
                ai.AddSkill(Skill.MeleeAttack, 75);
                ai.AddSkill(Skill.CastWeb, 25);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Golem:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.GOLEM,
                    new Color32(0xe6, 0x48, 0x2e, 255),
                    C.FSTR.Set("Gatekeeper"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(250, 5, 20, 250);
                var ai = new GolemMonster();
                ai.AddSkill(Skill.MeleeAttack, 60);
                ai.AddSkill(Skill.CastRandomFireball, 20);
                ai.AddSkill(Skill.CastLightning, 20);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.InvincibleThug:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.THUG,
                    Color.white,
                    C.FSTR.Set("Brigand"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(100, 2, 20, 0);
                var ai = new BasicMonster();
                ai.aggroRange = 40;
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.InvincibleBlockade:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.BRANCHES,
                    new Color32(0xbf, 0x79, 0x58, 255),
                    C.FSTR.Set("Blockade"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.fighter = new Fighter(9999, 9999, 1, 1);
                monster.e.ai      = null;
            }

            break;

            case MonsterType.Thug:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.THUG,
                    Color.white,
                    C.FSTR.Set("Brigand"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.moveTrail = new MoveTrail();
                monster.e.fighter   = new Fighter(40, 0, 6, 100);
                var ai = new BasicMonster();
                ai.aggroRange = 40;
                ai.AddSkill(Skill.MeleeAttack, 100);
                monster.e.ai = ai;
            }

            break;

            case MonsterType.Blockade:
            {
                monster = EntityStore.CreateEntity();
                monster.e.Initialize(
                    pos,
                    S.BRANCHES,
                    new Color32(0xbf, 0x79, 0x58, 255),
                    C.FSTR.Set("Blockade"),
                    RenderFunctions.RenderOrder.ACTOR,
                    true);

                monster.e.fighter = new Fighter(16, 0, 0, 0);
                monster.e.ai      = null;
            }

            break;
            }

            return(monster);
        }