public void MoveDirectly(string key, Position dest) { if (!NameToEntity.ContainsKey(key) || PosToName.ContainsKey(dest)) { return; } Entity e = NameToEntity[key]; Position pos = e.Pos; PosToName.Remove(pos); NameToEntity.Remove(key); Add(key, e.UpdateWith(pos: dest)); foreach (var k in NameToEntity.Keys) { if (NameToEntity[k].Faction == e.Faction) { NameToEntity[k] = NameToEntity[k].UpdateAlly(pos, dest); } else { NameToEntity[k] = NameToEntity[k].UpdateEnemy(pos, dest); } } // byName[key].Seeker.SetGoal(dest.Y, dest.X); // byPosition[dest].Seeker.SetGoal(dest.Y, dest.X); //Seeker.GetPath(Y, X); }
public void Add(string key, Entity val) { Entity v = val.UpdateWith(name: key); PosToName.Add(v.Pos, v.Name); NameToEntity.Add(key, v); }
public void Move(string key, int yMove, int xMove) { if (!NameToEntity.ContainsKey(key) || PosToName.ContainsKey(new Position(NameToEntity[key].Pos.Y + yMove, NameToEntity[key].Pos.X + xMove))) { return; } Entity e = NameToEntity[key]; Position pos = e.Pos; PosToName.Remove(pos); NameToEntity.Remove(key); e.Pos.Move(yMove, xMove); Add(key, e); foreach (var k in NameToEntity.Keys) { if (NameToEntity[k].Faction == e.Faction) { NameToEntity[k] = NameToEntity[k].UpdateAlly(pos, e.Pos); } else { NameToEntity[k] = NameToEntity[k].UpdateEnemy(pos, e.Pos); } } // byName[key].Seeker.SetGoal(e.Pos.Y, e.Pos.X); // byPosition[e.Pos].Seeker.SetGoal(e.Pos.Y, e.Pos.X); //Seeker.GetPath(Y, X); }
public EntityDictionary(ImmutableDictionary <string, Entity> ents) { NameToEntity = ents.ToBuilder(); PosToName = ImmutableDictionary <Position, string> .Empty.ToBuilder(); PosToName.AddRange(NameToEntity.ToDictionary(kv => kv.Value.Pos, kv => kv.Key)); }
public void Remove(Position key) { Entity e = NameToEntity[PosToName[key]]; NameToEntity.Remove(e.Name); PosToName.Remove(key); foreach (var k in NameToEntity.Keys) { NameToEntity[k] = NameToEntity[k].RemoveAll(e.Pos); } H.S.Initiative.CancelTurn(e.Name); }
public void Remove(string key) { Entity e = NameToEntity[key]; PosToName.Remove(e.Pos); NameToEntity.Remove(key); foreach (var k in NameToEntity.Keys) { NameToEntity[k] = NameToEntity[k].RemoveAll(e.Pos); } H.S.Initiative.CancelTurn(key); }
public Entity this[Position p] { get { if (PosToName.ContainsKey(p)) { return(NameToEntity[PosToName[p]]); } return(null); } set { if (value.Name == "") { throw new ArgumentException("Entity.Name must not be empty."); } PosToName[p] = value.Name; NameToEntity[value.Name] = value; } }
public Entity this[int y, int x] { get { Position p = new Position(y, x); if (PosToName.ContainsKey(p)) { return(NameToEntity[PosToName[p]]); } return(null); } set { if (value.Name == "") { throw new ArgumentException("Entity.Name must not be empty."); } Position p = new Position(y, x); Entity v = value.UpdateWith(pos: p); PosToName[p] = v.Name; NameToEntity[v.Name] = v; } }
public void UpdateAll(IEnumerable <Entity> vals) { NameToEntity.UpdateAll(vals.ToImmutableDictionary(e => e.Name)); PosToName.UpdateAll(vals.ToImmutableDictionary(e => e.Pos, e => e.Name)); }
public void Add(Entity val) { PosToName.Add(val.Pos, val.Name); NameToEntity.Add(val.Name, val); }
public bool Contains(Position p) { return(PosToName.ContainsKey(p)); }
public bool Contains(int y, int x) { return(PosToName.ContainsKey(new Position(y, x))); }