Esempio n. 1
0
        public static EntityReturner CreateGold(int x, int y, int rndNum)
        {
            // set bitwise to 0
            int checker = 0;

            List <Components.Component> compList = new List <Components.Component>();

            Components.PositionComp positionComp = new Components.PositionComp(x, y);
            compList.Add(positionComp);
            checker = checker | (int)Core.ComponentTypes.Position;

            Components.RenderComp rendComp = new Components.RenderComp('$', RLNET.RLColor.Yellow);
            compList.Add(rendComp);
            checker = checker | (int)Core.ComponentTypes.Render;

            Components.ItemValueComp valComp = new Components.ItemValueComp(RogueSharp.DiceNotation.Dice.Roll("1d6"));
            compList.Add(valComp);
            checker = checker | (int)Core.ComponentTypes.ItemValue;

            Components.CollectableComp collComp
                = new Components.CollectableComp(1, true, true, Types.ItemTypes.Treasure, true);
            compList.Add(collComp);
            checker = checker | (int)Core.ComponentTypes.Collectable;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 2
0
        public static EntityReturner CreateTrollClub()
        {
            List <Components.Component> compList = new List <Components.Component>();

            // set bitwise to 0
            int checker = 0;

            Components.WeaponComp weapComp = new Components.WeaponComp("2d6", Types.WeaponDmgTypes.Crushing, false, "Club", 12);
            compList.Add(weapComp);
            checker = checker | (int)ComponentTypes.Weapon;

            Components.UseableComp useComp = new Components.UseableComp();
            compList.Add(useComp);
            checker = checker | (int)ComponentTypes.Useable;

            Components.CollectableComp colComp = new Components.CollectableComp(1, false, false, Types.ItemTypes.Weapon, true);
            compList.Add(colComp);
            checker = checker | (int)ComponentTypes.Collectable;

            Components.ItemValueComp valComp = new Components.ItemValueComp(RogueSharp.DiceNotation.Dice.Roll("1d3"));
            compList.Add(valComp);
            checker = checker | (int)ComponentTypes.ItemValue;

            Components.RenderComp rendComp = new Components.RenderComp('|', Swatch.DbMetal);
            compList.Add(rendComp);
            checker = checker | (int)ComponentTypes.Render;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 3
0
        public static EntityReturner CreateHealthPotion()
        {
            List <Components.Component> compList = new List <Components.Component>();

            // set bitwise to 0
            int checker = 0;

            Components.PotionComp potComp = new Components.PotionComp(Types.PotionTypes.Health);
            compList.Add(potComp);
            checker = checker | (int)ComponentTypes.Potion;

            Components.UseableComp useComp = new Components.UseableComp();
            compList.Add(useComp);
            checker = checker | (int)ComponentTypes.Useable;

            Components.RenderComp rendComp = new Components.RenderComp('!', RLNET.RLColor.Yellow);
            compList.Add(rendComp);
            checker = checker | (int)Core.ComponentTypes.Render;

            Components.ItemValueComp valComp = new Components.ItemValueComp(RogueSharp.DiceNotation.Dice.Roll("1d6"));
            compList.Add(valComp);
            checker = checker | (int)Core.ComponentTypes.ItemValue;

            Components.CollectableComp collComp
                = new Components.CollectableComp(1, false, false, Types.ItemTypes.Potion, true);
            compList.Add(collComp);
            checker = checker | (int)Core.ComponentTypes.Collectable;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 4
0
        public static EntityReturner CreateStairs(int xp, int yp, bool isUp)
        {
            List <Components.Component> compList = new List <Components.Component>();

            // set bitwise to 0
            int checker = 0;

            Components.PositionComp positionComp = new Components.PositionComp(xp, yp);
            compList.Add(positionComp);
            checker = checker | (int)Core.ComponentTypes.Position;

            char c = isUp ? '<' : '>';

            Components.RenderComp rendComp = new Components.RenderComp(c, RLNET.RLColor.White);
            compList.Add(rendComp);
            checker = checker | (int)Core.ComponentTypes.Render;

            Components.StairComp stairComp = new Components.StairComp(isUp);
            compList.Add(stairComp);
            checker = checker | (int)Core.ComponentTypes.Stairs;

            Components.UseableComp useComp = new Components.UseableComp();
            compList.Add(useComp);
            checker = checker | (int)Core.ComponentTypes.Useable;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 5
0
        public static EntityReturner CreateDoor(int x, int y, bool isOpen)
        {
            List <Components.Component> compList = new List <Components.Component>();

            // set bitwise to 0
            int checker = 0;

            Components.PositionComp positionComp = new Components.PositionComp(x, y);
            compList.Add(positionComp);
            checker = checker | (int)Core.ComponentTypes.Position;

            char c = isOpen ? '-' : '+';

            Components.RenderComp rendComp = new Components.RenderComp(c, Colours.Door);
            compList.Add(rendComp);
            checker = checker | (int)Core.ComponentTypes.Render;

            Components.DoorComp doorComp = new Components.DoorComp(isOpen, false);
            compList.Add(doorComp);
            checker = checker | (int)Core.ComponentTypes.Door;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 6
0
        public static EntityReturner CreateKobold(int xPos, int yPos, string name, DungeonMap m)
        {
            List <Components.Component> compList = new List <Components.Component>();

            //stats
            int lev     = 1;
            int size    = 4;
            int intBase = 1;

            // set bitwise to 0
            int checker = 0;

            Components.PositionComp positionComp = new Components.PositionComp(xPos, yPos);
            compList.Add(positionComp);
            checker = checker | (int)Core.ComponentTypes.Position;

            Components.RenderComp rendComp = new Components.RenderComp('k', RLNET.RLColor.Green);
            compList.Add(rendComp);
            checker = checker | (int)Core.ComponentTypes.Render;

            Components.AttributesComp attComp = new Components.AttributesComp(15, size, lev, intBase);
            compList.Add(attComp);
            checker = checker | (int)Core.ComponentTypes.Attributes;

            //get base factor for health
            int hp = (int)(size + attComp.Hardiness) / 2;

            Components.HealthComp healthComp = new Components.HealthComp(hp);
            compList.Add(healthComp);
            checker = checker | (int)Core.ComponentTypes.Health;

            Components.ActorComp actComp = new Components.ActorComp();
            compList.Add(actComp);
            checker = checker | (int)Core.ComponentTypes.Actor;

            Components.AIComp aiComp = new Components.AIComp(m, Types.AITypes.Creature, new RogueSharp.Point(xPos, yPos));
            compList.Add(aiComp);
            checker = checker | (int)Core.ComponentTypes.AI;

            int speed = Game.Random.Next(2) + 1;

            Components.SchedulableComp shedComp = new Components.SchedulableComp(speed);
            compList.Add(shedComp);
            checker = checker | (int)Core.ComponentTypes.Schedulable;

            Components.InventoryComp invComp = new Components.InventoryComp();
            compList.Add(invComp);
            checker = checker | (int)Core.ComponentTypes.Inventory;

            Components.CreatureDetailsComp detailsComp
                = new Components.CreatureDetailsComp("Koblod", name, Types.CreatureTypes.Kobold);
            compList.Add(detailsComp);
            checker = checker | (int)ComponentTypes.CreatureDetails;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 7
0
        public static EntityReturner CreateTroll(int xPos, int yPos, string name, DungeonMap m)
        {
            List <Components.Component> compList = new List <Components.Component>();
            //stats
            int lev     = 2;
            int size    = 8 + RogueSharp.DiceNotation.Dice.Roll("1d3");
            int intBase = 1;

            // set bitwise to 0
            int checker = 0;

            Components.PositionComp positionComp = new Components.PositionComp(xPos, yPos);
            compList.Add(positionComp);
            checker = checker | (int)ComponentTypes.Position;

            Components.RenderComp rendComp = new Components.RenderComp('T', Core.Colours.OrcColour);
            compList.Add(rendComp);
            checker = checker | (int)ComponentTypes.Render;

            Components.AttributesComp attComp = new Components.AttributesComp(10, size, lev, intBase);
            compList.Add(attComp);
            checker = checker | (int)ComponentTypes.Attributes;

            //get base factor for health
            int hp = ((int)(size + attComp.Hardiness) / 2) * lev;

            Components.HealthComp healthComp = new Components.HealthComp(hp);
            compList.Add(healthComp);
            checker = checker | (int)ComponentTypes.Health;

            Components.ActorComp actComp = new Components.ActorComp();
            compList.Add(actComp);
            checker = checker | (int)ComponentTypes.Actor;

            Components.AIComp aiComp = new Components.AIComp(m, Types.AITypes.Creature, new RogueSharp.Point(xPos, yPos));
            compList.Add(aiComp);
            checker = checker | (int)ComponentTypes.AI;

            int speed = Game.Random.Next(3) + 6;

            Components.SchedulableComp shedComp = new Components.SchedulableComp(speed);
            compList.Add(shedComp);
            checker = checker | (int)ComponentTypes.Schedulable;

            Components.InventoryComp invComp = new Components.InventoryComp();
            compList.Add(invComp);
            checker = checker | (int)ComponentTypes.Inventory;

            Components.CreatureDetailsComp detailsComp
                = new Components.CreatureDetailsComp("Troll", name, Types.CreatureTypes.Troll);
            compList.Add(detailsComp);
            checker = checker | (int)ComponentTypes.CreatureDetails;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 8
0
        public static EntityReturner CreateZombie(int xPos, int yPos, string name, DungeonMap m)
        {
            List <Components.Component> compList = new List <Components.Component>();
            //stats
            int lev     = 2;
            int size    = 4 + RogueSharp.DiceNotation.Dice.Roll("1d3");
            int intBase = 1;

            // set bitwise to 0
            int checker = 0;

            Components.PositionComp positionComp = new Components.PositionComp(xPos, yPos);
            compList.Add(positionComp);
            checker = checker | (int)ComponentTypes.Position;

            Components.RenderComp rendComp = new Components.RenderComp('z', RLNET.RLColor.Cyan);
            compList.Add(rendComp);
            checker = checker | (int)ComponentTypes.Render;

            Components.AttributesComp attComp = new Components.AttributesComp(12, size, lev, intBase);
            compList.Add(attComp);
            checker = checker | (int)ComponentTypes.Attributes;

            //get base factor for health
            int hp = ((int)(size + attComp.Hardiness) / 2) * lev;

            Components.HealthComp healthComp = new Components.HealthComp(hp);
            compList.Add(healthComp);
            checker = checker | (int)ComponentTypes.Health;

            Components.ActorComp actComp = new Components.ActorComp();
            compList.Add(actComp);
            checker = checker | (int)ComponentTypes.Actor;

            Components.AIComp aiComp = new Components.AIComp(m, Types.AITypes.Undead, new RogueSharp.Point(xPos, yPos));
            compList.Add(aiComp);
            checker = checker | (int)ComponentTypes.AI;

            int speed = RogueSharp.DiceNotation.Dice.Roll("1d6") + 4;

            Components.SchedulableComp shedComp = new Components.SchedulableComp(speed);
            compList.Add(shedComp);
            checker = checker | (int)ComponentTypes.Schedulable;

            Components.CreatureDetailsComp detailsComp
                = new Components.CreatureDetailsComp("Zombie", name, Types.CreatureTypes.Zombie);
            compList.Add(detailsComp);
            checker = checker | (int)ComponentTypes.CreatureDetails;

            EntityReturner er = new EntityReturner(checker, compList);

            return(er);
        }
Esempio n. 9
0
        public void OnMessage(Core.MessageEventArgs e)
        {
            switch (e.MessageType)
            {
            case Core.EventTypes.CollisionCheck:

                Core.CollisionEventArgs details = (Core.CollisionEventArgs)e;
                //check entity manager lookup dict
                //string posKey = details.x.ToString() + "-" + details.y.ToString();
                bool       collision   = false;
                bool       openingDoor = false;
                List <int> deathList   = new List <int>();

                //if (_entityManager.EntityPostionLookUp.ContainsKey(posKey))

                int entIDRequestingMove = details.EntRequestingMove.UID;

                HashSet <int> innerIDS = _entityManager.Positions[details.y, details.x];
                foreach (int ids in innerIDS)
                {
                    // we have something there...

                    //List<Core.Entity> entL = _entityManager.EntityPostionLookUp[posKey];
                    Components.PositionComp pc
                        = (Components.PositionComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Position);

                    if (pc.X == details.x && pc.Y == details.y)
                    {
                        int checker = _entityManager.EntityBitLookUp[ids];
                        // is it a door?
                        if ((checker & (int)Core.ComponentTypes.Door) > 0)
                        {
                            Components.DoorComp doorComp =
                                (Components.DoorComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Door);

                            if (!doorComp.IsOpen)
                            {
                                openingDoor     = true;
                                doorComp.IsOpen = true;
                                _dungeonMap.SetCellProperties(pc.X, pc.Y, true, true);
                                Components.RenderComp rc = (Components.RenderComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Render);
                                rc.Glyph = '-';
                            }
                        }


                        //is it something living?
                        if ((checker & (int)Core.ComponentTypes.Health) > 0)
                        {
                            //Game.MessageLog.Add("FIGHT NOW");
                            collision = true;

                            //get details of person being hit
                            Components.HealthComp hComp =
                                (Components.HealthComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Health);
                            Components.AttributesComp attComp
                                = (Components.AttributesComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Attributes);

                            Components.CreatureDetailsComp detailsComp =
                                (Components.CreatureDetailsComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.CreatureDetails);
                            bool isUndead = detailsComp.Undead;

                            Components.AIComp aiComp = (Components.AIComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.AI);

                            // get hitter details
                            Components.AttributesComp attOfHitterComp
                                = (Components.AttributesComp)_entityManager.GetSingleComponentByID(entIDRequestingMove, Core.ComponentTypes.Attributes);

                            bool hit = false;
                            // base damage = 1
                            int dmg         = 1;
                            int attackSkill = (int)(attComp.Strength + attComp.Dexterity) / 2;

                            if (RogueSharp.DiceNotation.Dice.Roll("1d20") < attackSkill)
                            {
                                hit = true;

                                // get weapon we are using
                                Components.InventoryComp invComp
                                    = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entIDRequestingMove, Core.ComponentTypes.Inventory);

                                // get damage bonus
                                int dmgBonus = RogueSharp.DiceNotation.Dice.Roll(attOfHitterComp.DmgBonus);
                                dmgBonus *= attOfHitterComp.DmgMod;

                                if (invComp != null)
                                {
                                    if (invComp.CurrentWeapon > 0)
                                    {
                                        Components.WeaponComp weapon
                                            = (Components.WeaponComp)_entityManager.GetSingleComponentByID(invComp.CurrentWeapon, Core.ComponentTypes.Weapon);

                                        dmg = RogueSharp.DiceNotation.Dice.Roll(weapon.DamageBase);
                                    }
                                }
                                int totalDamage = dmgBonus + dmg;
                                if (totalDamage <= 1)
                                {
                                    totalDamage = 1;
                                }
                                hComp.Health -= totalDamage;
                                if (hComp.Health < 0)
                                {
                                    hComp.Health = 0;
                                }

                                attComp.Morale -= totalDamage;
                                if (attComp.Morale < 1)
                                {
                                    attComp.Morale = 0;
                                }

                                if (hComp.Health < (hComp.MaxHealth * 0.2))
                                {
                                    if (!isUndead)
                                    {
                                        aiComp.Fleeing = true;
                                    }
                                }
                            }


                            aiComp.UnderAttack = true;

                            aiComp.LastBasher = entIDRequestingMove;
                            if (!aiComp.CurrentEnemies.Contains(entIDRequestingMove))
                            {
                                aiComp.CurrentEnemies.Add(entIDRequestingMove);
                            }
                            Components.CreatureDetailsComp cdComp =
                                (Components.CreatureDetailsComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.CreatureDetails);
                            List <Components.Component>    ourList = _entityManager.GetCompsByID(details.EntRequestingMove.UID);
                            Components.CreatureDetailsComp ourComp =
                                (Components.CreatureDetailsComp)ourList.FirstOrDefault(x => x.CompType == Core.ComponentTypes.CreatureDetails);
                            if (hit)
                            {
                                Game.MessageLog.Add($"{ourComp.PersonalName} Bashes {cdComp.PersonalName} for {dmg} Damage");
                            }
                            else
                            {
                                Game.MessageLog.Add($"{ourComp.PersonalName} Misses {cdComp.PersonalName}");
                            }


                            if (hComp.Health < 1)
                            {
                                // entity is dead, collect up and kill at end
                                deathList.Add(ids);
                            }
                        }
                    }
                }

                foreach (int i in deathList)
                {
                    Core.DeleteEntEventArgs msg = new Core.DeleteEntEventArgs(Core.EventTypes.DeadEntity, i);
                    Core.EventBus.Publish(Core.EventTypes.DeadEntity, msg);
                }

                if (!collision)
                {
                    // move okay
                    Core.MoveOkayEventArgs msg = new Core.MoveOkayEventArgs(Core.EventTypes.MoveOK, details.EntRequestingMove, details.x, details.y);
                    Core.EventBus.Publish(Core.EventTypes.MoveOK, msg);
                }
                else     //if (!openingDoor)
                {
                    //    // fight on
                    Core.NoMoveEventArgs msg = new Core.NoMoveEventArgs(Core.EventTypes.NoMove, details.EntRequestingMove);
                    Core.EventBus.Publish(Core.EventTypes.NoMove, msg);
                }
                break;
            }
        }
Esempio n. 10
0
        public Dictionary <int, List <Components.Component> > LoadEntities()
        {
            Dictionary <int, List <Components.Component> > returnDict
                = new Dictionary <int, List <Components.Component> >();

            string inputJson = System.IO.File.ReadAllText("ents.json");

            Dictionary <int, Dictionary <Core.ComponentTypes, List <Dictionary <string, string> > > > output
                = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <int, Dictionary <Core.ComponentTypes, List <Dictionary <string, string> > > > >(inputJson);

            foreach (KeyValuePair <int, Dictionary <Core.ComponentTypes, List <Dictionary <string, string> > > > entry in output)
            {
                int         eid = entry.Key;
                Core.Entity ent = new Core.Entity(eid);

                List <Components.Component> componentList = new List <Components.Component>();

                Dictionary <Core.ComponentTypes, List <Dictionary <string, string> > > compDict
                    = entry.Value;

                foreach (KeyValuePair <Core.ComponentTypes, List <Dictionary <string, string> > > inner in compDict)
                {
                    if (inner.Key == Core.ComponentTypes.Position)
                    {
                        List <Dictionary <string, string> > comps = inner.Value;
                        foreach (Dictionary <string, string> cDict in comps)
                        {
                            int x = Int32.Parse(cDict["X"]);
                            int y = Int32.Parse(cDict["Y"]);

                            Components.PositionComp pc = new Components.PositionComp(x, y);
                            componentList.Add(pc);
                        }
                    }
                    else if (inner.Key == Core.ComponentTypes.Render)
                    {
                        List <Dictionary <string, string> > comps = inner.Value;
                        foreach (Dictionary <string, string> cDict in comps)
                        {
                            char          glyph = cDict["Glyph"][0];
                            float         r     = float.Parse(cDict["ColorR"]);
                            float         g     = float.Parse(cDict["ColorG"]);
                            float         b     = float.Parse(cDict["ColorB"]);
                            RLNET.RLColor c     = new RLNET.RLColor(r, g, b);

                            Components.RenderComp rc = new Components.RenderComp(glyph, c);
                            componentList.Add(rc);
                        }
                    }
                    //else if (inner.Key == Core.ComponentTypes.Health)
                    //{
                    //    List<Dictionary<string, string>> comps = inner.Value;
                    //    foreach (Dictionary<string, string> cDict in comps)
                    //    {
                    //        int h = Int32.Parse(cDict["Health"]);
                    //        int mh = Int32.Parse(cDict["MaxHealth"]);

                    //        Components.HealthComp msc = new Components.HealthComp();
                    //        msc.Health = h;
                    //        msc.MaxHealth = mh;

                    //        componentList.Add(msc);
                    //    }
                    //}
                    //else if (inner.Key == Core.ComponentTypes.Attributes)
                    //{
                    //    List<Dictionary<string, string>> comps = inner.Value;
                    //    foreach (Dictionary<string, string> cDict in comps)
                    //    {
                    //        int aw = Int32.Parse(cDict["Awareness"]);

                    //        Components.AttributesComp msc = new Components.AttributesComp(aw);

                    //        componentList.Add(msc);
                    //    }
                    //}
                    //else if (inner.Key == Core.ComponentTypes.AI)
                    //{
                    //    List<Dictionary<string, string>> comps = inner.Value;
                    //    foreach (Dictionary<string, string> cDict in comps)
                    //    {
                    //        bool aw = bool.Parse(cDict["HasAI"]);

                    //        Components.AIComp msc = new Components.AIComp();
                    //        msc.HasAI = aw;
                    //        componentList.Add(msc);
                    //    }
                    //}
                }
                returnDict.Add(eid, componentList);
            }
            return(returnDict);
        }
Esempio n. 11
0
        public void OnMessage(Core.MessageEventArgs e)
        {
            switch (e.MessageType)
            {
            case Core.EventTypes.DeleteEntity:
                Core.DeleteEntEventArgs msg = (Core.DeleteEntEventArgs)e;

                //_entsToDelete.Add(msg.entID);
                // set cell walkable
                List <Components.Component> compList = _entityManager.GetCompsByID(msg.entID);
                Components.PositionComp     pc
                    = (Components.PositionComp)compList.FirstOrDefault(x => x.CompType == Core.ComponentTypes.Position);
                _dungeonMap.SetIsWalkable(pc.X, pc.Y, true);

                _shedSystem.Remove(_entityManager.JustEntities[msg.entID]);
                _entityManager.RemoveEntity(msg.entID);
                break;

            case Core.EventTypes.DeadEntity:

                // leave corpse of entity

                Core.DeleteEntEventArgs dM = (Core.DeleteEntEventArgs)e;
                int entID = dM.entID;

                Components.PositionComp posC = (Components.PositionComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Position);
                _dungeonMap.SetIsWalkable(posC.X, posC.Y, true);

                Components.RenderComp rendC = (Components.RenderComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Render);
                rendC.Glyph  = '%';
                rendC.Colour = RLNET.RLColor.LightRed;

                Components.AttributesComp attC = (Components.AttributesComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Attributes);
                attC.Dead = true;
                Game.MessageLog.Add($"ENT IS DEAD YEAH: {attC.Dead}   ----------------------------------------------------------------------------");

                _shedSystem.Remove(_entityManager.JustEntities[entID]);

                _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Health);
                _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Actor);
                _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Schedulable);

                _entityManager.AddFurnitureToEnt(entID);
                _entityManager.AddDeadComp(entID);

                // drop inventory
                Components.InventoryComp invC = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Inventory);
                if (invC != null)
                {
                    foreach (int droppedID in invC.Inventory)
                    {
                        Components.CollectableComp cc = (Components.CollectableComp)_entityManager.GetSingleComponentByID(droppedID, Core.ComponentTypes.Collectable);
                        // only drop treasure for the moment
                        //TODO - drop other items apart from treasure
                        if (cc.Treasure)
                        {
                            _entityManager.AddPositionToEnt(droppedID, posC.X, posC.Y);
                            cc.Active = true;
                        }
                    }
                }
                break;
            }
        }
Esempio n. 12
0
        public void Update(RLConsole console, RLConsole statsConsole)
        {
            var posBit     = (int)Core.ComponentTypes.Position;
            var rendBit    = (int)Core.ComponentTypes.Render;
            int statBit    = (int)Core.ComponentTypes.Health;
            int detailsBit = (int)Core.ComponentTypes.CreatureDetails;
            int yPos       = 16;
            int xPos       = 2;

            Dictionary <int, int> ents = EntityManager.EntityBitLookUp;

            foreach (KeyValuePair <int, int> pair in ents)
            {
                int eid          = pair.Key;
                int furnitureRes = (int)Core.ComponentTypes.Furniture & pair.Value;
                if (furnitureRes > 0)
                {
                    Components.RenderComp   rc = (Components.RenderComp)EntityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Render);
                    Components.PositionComp pc = (Components.PositionComp)EntityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Position);
                    console.Set(pc.X, pc.Y, rc.Colour, Core.Colours.FloorBackground, rc.Glyph);
                }
            }

            foreach (KeyValuePair <int, int> pair in ents)
            {
                int res    = posBit & pair.Value;
                int res2   = rendBit & pair.Value;
                int actRes = (int)Core.ComponentTypes.Actor & pair.Value;

                char    renderChar = 'X';
                RLColor c          = RLColor.White;

                List <Components.Component> comps = EntityManager.GetCompsByID(pair.Key);

                if ((res > 0 && res2 > 0) && (actRes == 0))
                {
                    Components.RenderComp rendComp
                        = (Components.RenderComp)comps.Find(s => s.CompType == Core.ComponentTypes.Render);

                    Components.PositionComp posComp =
                        (Components.PositionComp)comps.Find(s => s.CompType == Core.ComponentTypes.Position);

                    if (rendComp != null && posComp != null)
                    {
                        console.Set(posComp.X, posComp.Y, rendComp.Colour,
                                    Core.Colours.FloorBackground, rendComp.Glyph);
                    }
                    if (rendComp != null)
                    {
                        renderChar = rendComp.Glyph;
                        c          = rendComp.Colour;
                    }
                }

                //draw stats
            }
            foreach (KeyValuePair <int, int> pair in ents)
            {
                // draw only actors on top
                if ((pair.Value & (int)Core.ComponentTypes.Actor) > 0)
                {
                    List <Components.Component> comps = EntityManager.GetCompsByID(pair.Key);

                    Components.RenderComp rendComp = (Components.RenderComp)comps.Find(s => s.CompType == Core.ComponentTypes.Render);

                    Components.PositionComp posComp =
                        (Components.PositionComp)comps.Find(s => s.CompType == Core.ComponentTypes.Position);
                    Components.AIComp aiComp = (Components.AIComp)comps.Find(x => x.CompType == Core.ComponentTypes.AI);

                    RLColor rColor;

                    if (aiComp.Fleeing)
                    {
                        rColor = RLColor.Red;
                    }
                    else
                    {
                        rColor = rendComp.Colour;
                    }

                    if (rendComp != null && posComp != null)
                    {
                        console.Set(posComp.X, posComp.Y, rColor,
                                    Core.Colours.FloorBackground, rendComp.Glyph);
                    }

                    int res3 = statBit & pair.Value;
                    if (res3 > 0)
                    {
                        Components.HealthComp healthStat =
                            (Components.HealthComp)comps.Find(s => s.CompType == Core.ComponentTypes.Health);

                        Components.CreatureDetailsComp detailsComp =
                            (Components.CreatureDetailsComp)comps.Find(x => x.CompType == Core.ComponentTypes.CreatureDetails);

                        Components.InventoryComp invComp = (Components.InventoryComp)comps.Find(x => x.CompType == Core.ComponentTypes.Inventory);

                        if (healthStat != null && detailsComp != null)
                        {
                            statsConsole.Print(xPos, yPos, detailsComp.PersonalName + " the " + detailsComp.Name, rendComp.Colour);
                            yPos++;
                            statsConsole.Print(xPos, yPos, rendComp.Glyph.ToString(), rendComp.Colour);
                            int width
                                = Convert.ToInt32(((double)healthStat.Health / (double)healthStat.MaxHealth) * 16);
                            int remainingWidth = 16 - width;
                            statsConsole.SetBackColor(xPos + 2, yPos, width, 1, Core.Swatch.Primary);
                            statsConsole.SetBackColor(xPos + 2 + width, yPos, remainingWidth, 1, Core.Swatch.PrimaryDarkest);
                            statsConsole.Print(xPos + 2, yPos, $": {healthStat.Health.ToString()}", Core.Swatch.DbLight);
                            yPos++;
                            if (invComp != null)
                            {
                                statsConsole.Print(xPos, yPos, $"Carrying {invComp.Treasure.Count.ToString()} Gold", rendComp.Colour);
                            }
                            yPos = yPos + 2;
                        }
                    }
                }
            }
            // stats console
            int count = 0;

            for (int yp = 0; yp < EntityManager.GetHeight(); yp++)
            {
                for (int xp = 0; xp < EntityManager.GetWidth(); xp++)
                {
                    if (EntityManager.Positions[yp, xp].Count > 0)
                    {
                        HashSet <int> ent = EntityManager.Positions[yp, xp];

                        foreach (int indvID in ent)
                        {
                            List <Components.Component> inner = EntityManager.Entities[indvID];
                            foreach (Components.Component ec in inner)
                            {
                                if (ec.CompType == Core.ComponentTypes.Collectable)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }

            statsConsole.Print(1, 1, $"collectables=: {count.ToString()}", Core.Colours.TextHeading);
        }