Пример #1
0
        private EntityInfo CreateBaseEntityInfoFromTileEntity(TileEntity te)
        {
            EntityInfo toReturn = new EntityInfo(te.GetUid());

            toReturn.Health   = te.Health;
            toReturn.Position = positionDict[te.GetUid()];

            return(toReturn);
        }
Пример #2
0
 public Vector2Int GetTileEntityPosition(TileEntity tileEntity)
 {
     if (positionDict.ContainsKey(tileEntity.GetUid()))
     {
         return(positionDict[tileEntity.GetUid()]);
     }
     else
     {
         return(TileEntityConstants.UNDEFINED_POSITION);
     }
 }
Пример #3
0
        private void UpdateTileEntityPosition(TileEntity tileEntity, Vector2Int from, Vector2Int to)
        {
            Tile fromTile = GetTile(from);
            Tile toTile   = GetTile(to);

            if (fromTile.Equals(toTile))
            {
                // Nothing to do
                return;
            }

            fromTile.RemoveTileEntity(tileEntity);
            // Place on new tile
            toTile.AddTileEntity(tileEntity);

            // Update the entity's position
            UpdateOrAddToPositionDictionary(tileEntity, to);

            // Get or create EntityInfo
            EntityInfo info = gameInfo.GetEntityInfoOrDefault(tileEntity.GetUid(), CreateBaseEntityInfoFromTileEntity(tileEntity));

            info.Position = to;
            gameInfo.UpdateOrAddToEntityInfoDictionary(info);
            Debug.Log(gameInfo.ToString());
        }
Пример #4
0
        public void DoDamageToTileEntity(TileEntity te, int damage)
        {
            int damageDealt = te.TakeDamage(damage);

            Debug.Log(te.GetName() + " was shot for " + damageDealt + " damage ");

            EntityInfo info = gameInfo.GetEntityInfoOrDefault(te.GetUid(), CreateBaseEntityInfoFromTileEntity(te));

            gameInfo.UpdateOrAddToEntityInfoDictionary(info);
        }
Пример #5
0
        public void DoMoveTileEntity(TileEntity tileEntity, Vector2Int direction, bool allowOverlap)
        {
            Vector2Int curPosition;

            if (positionDict.TryGetValue(tileEntity.GetUid(), out curPosition))
            {
                Vector2Int newPosition = UpdatePosition(curPosition, direction, allowOverlap);
                UpdateTileEntityPosition(tileEntity, curPosition, newPosition);
            }
            else
            {
                Debug.Log("[GameBoard] Failed to move tileEntity... not in dictionary!");
            }
        }
Пример #6
0
        public void AddEntityToTile(int row, int column, TileEntity tileEntity)
        {
            if (row > height || column > width || row < 0 || column < 0)
            {
                Debug.Log("[GameBoard] Cannot add entity to tile: (" + row + "," + column + ")");
                return;
            }

            if (boardArray[row, column] == null)
            {
                Debug.Log("[GameBoard] Cannot add entity to tile: (" + row + "," + column + ")");
                return;
            }
            boardArray[row, column].AddEntity(tileEntity);

            if (positionDict.ContainsKey(tileEntity.GetUid()))
            {
                positionDict[tileEntity.GetUid()] = new Vector2Int(row, column);
            }
            else
            {
                positionDict.Add(tileEntity.GetUid(), new Vector2Int(row, column));
            }
        }
Пример #7
0
 private bool UpdateOrAddToPositionDictionary(TileEntity te, Vector2Int value)
 {
     return(UpdateOrAddToPositionDictionary(te.GetUid(), value));
 }