Beispiel #1
0
 private void ChangeOwnership()
 {
     for (var i = 0; i < scoreTrackers.Count; i++)
     {
         ScoreTracker tracker        = scoreTrackers[i];
         TileVisitor  trackerVisitor = tracker.gameObject.GetComponent <TileVisitor>();
         if (trackerVisitor.CurrentlyVisiting.GetTotalNumberOfVisitors(tagForPoints) > 0)
         {
             foreach (TileVisitor otherOccupant in trackerVisitor.CurrentlyVisiting.GetVisitorsOfTag(tagForPoints))
             {
                 PointsGiver pointsGiver = otherOccupant.gameObject.GetComponent <PointsGiver>();
                 if (pointsGiver != null)
                 {
                     if (pointsGiver.OwnedBy != tracker)
                     {
                         //TODO: Handle line of sight exclusion!
                         pointsGiver.OwnedBy = tracker;
                         animationManager.AddNewTakeOver(tracker, pointsGiver);
                     }
                 }
                 else
                 {
                     Debug.LogError("Gameobject: " + otherOccupant.gameObject.name + " is tagged as " +
                                    tagForPoints +
                                    " but doesn't have a pointsgiver object!");
                 }
             }
         }
     }
 }
Beispiel #2
0
 public void AcceptVisitor(TileVisitor visitor)
 {
     if (!visitors.ContainsKey(visitor.Tag))
     {
         visitors.Add(visitor.Tag, new List <TileVisitor> ());
     }
     visitors [visitor.Tag].Add(visitor);
 }
Beispiel #3
0
 private void SaveOriginalPositions()
 {
     originalPositions.Clear();
     foreach (KeyValuePair <MoveProvider, List <Move> > entry in movesPerProvider)
     {
         TileVisitor visitor = entry.Key.gameObject.GetComponent <TileVisitor>();
         originalPositions.Add(visitor.gameObject, visitor.CurrentlyVisiting);
     }
 }
    void Start()
    {
        myVisitor = GetComponent <TileVisitor> ();
        if (myVisitor == null)
        {
            Debug.LogError("I need a TileVisitor to drive!");
        }
        Tile newTile = grid.GetTileAt(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y));

        myVisitor.CurrentlyVisiting = newTile;
    }
Beispiel #5
0
 private void UpdatePositionsBasedOnInput()
 {
     foreach (KeyValuePair <MoveProvider, List <Move> > entry in movesPerProvider)
     {
         Move currentMove = entry.Value[currentTurn];
         if (currentMove == Move.STAY)
         {
             continue;
         }
         TileVisitor visitor = entry.Key.gameObject.GetComponent <TileVisitor>();
         Direction   moveIn  = MoveUtils.GetDirectionFor(currentMove);
         if (visitor.CurrentlyVisiting.canMove(moveIn))
         {
             animationManager.SetNewTileLocation(visitor.gameObject, visitor.CurrentlyVisiting);
             visitor.CurrentlyVisiting = visitor.CurrentlyVisiting.GetNeighbor(moveIn);
         }
     }
 }
Beispiel #6
0
    public void BidVisitorFarewell(TileVisitor visitor)
    {
        string tag = visitor.Tag;

        if (!visitors.ContainsKey(tag))
        {
            Debug.LogError("This tile doesn't contain the given visitor");
        }
        if (!visitors [tag].Contains(visitor))
        {
            Debug.LogError("This tile doesn't contain the given visitor");
        }
        visitors [tag].Remove(visitor);
        if (visitors [tag].Count <= 0)
        {
            visitors.Remove(tag);
        }
    }
Beispiel #7
0
    private void CheckValidityAndHandlePushBacks()
    {
        int conflicts = 1;

        while (conflicts > 0)
        {
            conflicts = 0;
            List <TileVisitor> toPushBack = new List <TileVisitor>();
            foreach (KeyValuePair <GameObject, Tile> pair in originalPositions)
            {
                GameObject  dude        = pair.Key;
                TileVisitor tileVisitor = dude.GetComponent <TileVisitor>();
                if (tileVisitor.CurrentlyVisiting.GetTotalNumberOfVisitors(tileVisitor.Tag) > 1)
                {
                    //TODO: Mark this as a conflict, and notify the animation handler...somehow, so we can play the fight animations
                    conflicts++;
                    toPushBack.AddRange(tileVisitor.CurrentlyVisiting.GetVisitorsOfTag(tileVisitor.Tag));
                }
            }
            foreach (TileVisitor visitor in toPushBack)
            {
                if (originalPositions.ContainsKey(visitor.gameObject))
                {
                    Tile sourceTile = originalPositions[visitor.gameObject];
                    if (visitor.CurrentlyVisiting != sourceTile)
                    {
                        animationManager.SetNewCollision(visitor.gameObject, visitor.CurrentlyVisiting);
                        visitor.CurrentlyVisiting = originalPositions[visitor.gameObject];
                    }
                }
                else
                {
                    Debug.LogError("Unable to push back " + visitor.gameObject.name +
                                   " because their original position isn't known!");
                }
            }
        }
    }