Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void Add(string key, Entity val)
        {
            Entity v = val.UpdateWith(name: key);

            PosToName.Add(v.Pos, v.Name);
            NameToEntity.Add(key, v);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 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;
     }
 }
Beispiel #8
0
 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;
     }
 }
Beispiel #9
0
 public void UpdateAll(IEnumerable <Entity> vals)
 {
     NameToEntity.UpdateAll(vals.ToImmutableDictionary(e => e.Name));
     PosToName.UpdateAll(vals.ToImmutableDictionary(e => e.Pos, e => e.Name));
 }
Beispiel #10
0
 public void Add(Entity val)
 {
     PosToName.Add(val.Pos, val.Name);
     NameToEntity.Add(val.Name, val);
 }
Beispiel #11
0
 public bool Contains(Position p)
 {
     return(PosToName.ContainsKey(p));
 }
Beispiel #12
0
 public bool Contains(int y, int x)
 {
     return(PosToName.ContainsKey(new Position(y, x)));
 }