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); }
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); }
public void RemoveEntity(int eid) { if (Entities.ContainsKey(eid)) { List <Components.Component> compList = Entities[eid]; if (compList.Exists(x => x.CompType == Core.ComponentTypes.Position)) { Components.PositionComp posComp = (Components.PositionComp)GetSingleComponentByID(eid, Core.ComponentTypes.Position); RemoveEntFromPosition(posComp.X, posComp.Y, eid); //string lu = posComp.X.ToString() + "-" + posComp.Y.ToString(); //if (EntityPostionLookUp.ContainsKey(lu)) //{ // List<Core.Entity> entList = EntityPostionLookUp[lu]; // entList.RemoveAll(x => x.UID == eid); // if (entList.Count == 0) // { // EntityPostionLookUp.Remove(lu); // } //} } JustEntities.Remove(eid); Entities.Remove(eid); EntityBitLookUp.Remove(eid); } }
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); }
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); }
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); }
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); }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.Use: Core.UseEventArgs args = (Core.UseEventArgs)e; // position based? if (args.PositionBased) { Core.Entity entityUsing = args.EntityUsing; Components.PositionComp posComp = (Components.PositionComp)_entManager.GetSingleComponentByID(entityUsing.UID, Core.ComponentTypes.Position); int xPos = posComp.X; int yPos = posComp.Y; string posLU = xPos.ToString() + "-" + yPos.ToString(); if (_entManager.EntityPostionLookUp.TryGetValue(posLU, out List <Core.Entity> entry)) { foreach (Core.Entity li in entry) { int useableLU = (int)Core.ComponentTypes.Useable; int stairsLU = (int)Core.ComponentTypes.Stairs; int entBit = _entManager.EntityBitLookUp[li.UID]; if ((useableLU & entBit) > 0) { // is it a stair? if ((entBit & stairsLU) > 0) { // yay! it's a stair.... Components.StairComp stairComp = (Components.StairComp)_entManager.GetSingleComponentByID(li.UID, Core.ComponentTypes.Stairs); if (stairComp.isUp) { // go up } else { //go down } } } } } } else { // non position based, use inventory } break; } }
public void AddPositionToEnt(int eid, int x, int y) { Components.PositionComp pC = new Components.PositionComp(x, y); List <Components.Component> entComps = Entities[eid]; entComps.Add(pC); int checker = EntityBitLookUp[eid]; checker = checker | (int)Core.ComponentTypes.Position; EntityBitLookUp[eid] = checker; AddEntToPosition(x, y, eid); }
public void UpdateFOVForMonsters(Systems.EntityManager em) { int bitmask = ((int)ComponentTypes.Attributes | (int)ComponentTypes.Position); List <int> entList = em.GetEntIDByBit(bitmask); Dictionary <int, List <Components.Component> > entities = em.GetEntities(); List <Components.Component> cList; foreach (int ent in entList) { if (entities.TryGetValue(ent, out cList)) { int aware; int x, y; Components.PositionComp pos = (Components.PositionComp)cList.Find(s => s.CompType == ComponentTypes.Position); if (pos != null) { Components.AttributesComp at = (Components.AttributesComp)cList.Find(s => s.CompType == ComponentTypes.Attributes); if (at != null) { aware = at.Awareness; x = pos.X; y = pos.Y; ComputeFov(x, y, aware, true); foreach (RogueSharp.Cell cell in GetAllCells()) { if (IsInFov(cell.X, cell.Y)) { SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true); } } } } } } }
public static EntityReturner CreateHealthPotionAtLocation(int x, int y) { 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)ComponentTypes.Position; 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); }
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; } }
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); }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.ActionReqMove: // request movement Core.MovementReqEventArgs moveReq = (Core.MovementReqEventArgs)e; Core.Entity entoToMove = moveReq.EntRequestingMove; int eid = entoToMove.UID; Core.Directions dirToMove = moveReq.Direction; Components.PositionComp posComp = (Components.PositionComp)_entityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Position); int newX = posComp.X; int newY = posComp.Y; switch (dirToMove) { case Core.Directions.None: break; case Core.Directions.DownLeft: newX = posComp.X - 1; newY = posComp.Y + 1; break; case Core.Directions.Down: newX = posComp.X; newY = posComp.Y + 1; break; case Core.Directions.DownRight: newX = posComp.X + 1; newY = posComp.Y + 1; break; case Core.Directions.Left: newX = posComp.X - 1; newY = posComp.Y; break; case Core.Directions.Centre: break; case Core.Directions.Right: newX = posComp.X + 1; newY = posComp.Y; break; case Core.Directions.UpLeft: newX = posComp.X - 1; newY = posComp.Y - 1; break; case Core.Directions.Up: newX = posComp.X; newY = posComp.Y - 1; break; case Core.Directions.UpRight: newX = posComp.X + 1; newY = posComp.Y - 1; break; } //check for collision Core.CollisionEventArgs msg = new Core.CollisionEventArgs(Core.EventTypes.CollisionCheck, entoToMove, newX, newY); Core.EventBus.Publish(Core.EventTypes.CollisionCheck, msg); break; case Core.EventTypes.MoveOK: Core.MoveOkayEventArgs m = (Core.MoveOkayEventArgs)e; if (_dungeonMap.GetCell(m.newX, m.newY).IsWalkable) { // get current pos Core.Entity ent = m.EntRequestingMove; Components.PositionComp pos = (Components.PositionComp)_entityManager.GetSingleComponentByID(ent.UID, Core.ComponentTypes.Position); Components.AIComp aiComp = (Components.AIComp)_entityManager.GetSingleComponentByID(ent.UID, Core.ComponentTypes.AI); aiComp.TurnsSinceMove = 0; _dungeonMap.SetIsWalkable(pos.X, pos.Y, true); _entityManager.RemoveEntFromPosition(pos.X, pos.Y, ent.UID); pos.X = m.newX; pos.Y = m.newY; _dungeonMap.SetIsWalkable(m.newX, m.newY, false); _entityManager.AddEntToPosition(m.newX, m.newY, ent.UID); } break; case Core.EventTypes.DirectMove: Core.DirectMoveEventArgs dm = (Core.DirectMoveEventArgs)e; //check for collision Core.CollisionEventArgs checkMsg = new Core.CollisionEventArgs(Core.EventTypes.CollisionCheck, dm.EntRequestingMove, dm.PointToMoveTo.X, dm.PointToMoveTo.Y); Core.EventBus.Publish(Core.EventTypes.CollisionCheck, checkMsg); break; case Core.EventTypes.NoMove: Core.NoMoveEventArgs nmEvent = (Core.NoMoveEventArgs)e; Components.AIComp aiC = (Components.AIComp)_entityManager.GetSingleComponentByID(nmEvent.EntNotMoving.UID, Core.ComponentTypes.AI); if (aiC != null) { aiC.TurnsSinceMove++; } //Game.MessageLog.Add($"Turns Since = {aiC.TurnsSinceMove.ToString()}"); break; } }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.InventoryAdd: Core.InventoryAddEventArgs msg = (Core.InventoryAddEventArgs)e; int entPickingUp = msg.EntPickingUp; int pickedUpObj = msg.PickedUpObject; List <Components.Component> pickedUpObjComps = _entityManager.GetCompsByID(pickedUpObj); List <Components.Component> entComps = _entityManager.GetCompsByID(entPickingUp); Components.InventoryComp invComp = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entPickingUp, Core.ComponentTypes.Inventory); if (invComp != null) { Components.PositionComp posComp = (Components.PositionComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.Position); Components.CollectableComp collectComp = (Components.CollectableComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.Collectable); Components.ItemValueComp vC = (Components.ItemValueComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.ItemValue); //Components.Component c = _entityManager.GetSingleComponentByID(collectComp.) bool hasValue = (vC != null); if (collectComp.Active) { //is it treasure? if (collectComp.Treasure) { //TODO stackable treasure if (vC != null) { invComp.ValueCarried += vC.ItemValue; } // remove position comps from picked up object _entityManager.RemoveCompFromEnt(pickedUpObj, Core.ComponentTypes.Position); collectComp.Active = false; _entityManager.RemoveEntFromPosition(posComp.X, posComp.Y, pickedUpObj); invComp.Treasure.Add(pickedUpObj); } else { // is it stackable? - not currently used //TODO stackable collectables if (collectComp.Stackable) { } else { Game.MessageLog.Add("picking up item"); // System.Threading.Thread.Sleep(1000); if (posComp != null) { _entityManager.RemoveEntFromPosition(posComp.X, posComp.Y, pickedUpObj); _entityManager.RemoveCompFromEnt(pickedUpObj, Core.ComponentTypes.Position); pickedUpObjComps.Remove(posComp); } invComp.Inventory.Add(pickedUpObj); } } } } break; } }
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; } }
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); }