コード例 #1
0
            public void DrawAOOTLines(List <ATTile> path)
            {
                DestroyAOOPLines();
                for (int i = 0; i < path.Count - 1; i++)
                {
                    ATTile t = path [i];


                    if (t.FirstOccupant != actor.TileMovement)
                    {
                        continue;
                    }

                    ATTile n = path [i + 1];

                    foreach (Actor a in t.Reachers)
                    {
                        if (a.EnemiesWith(actor) &&
                            !n.Reachers.Contains(a) &&
                            !a.UsedReaction())
                        {
                            DrawAOOPLineFrom(a.transform.position, actor.transform.position);
                            //Draw line/sword from a to char....
                        }
                    }
                }
            }
コード例 #2
0
            public void ActorMovedOutOfTile(ATTile current, ATTile dest)
            {
                movesThisRound += dest.MoveCostFor(this);
                foreach (Actor a in current.Reachers)
                {
                    if (!a.EnemiesWith(this))
                    {
                        continue;
                    }
                    //If you are moving out of a tile within reach for this reacher....
                    if (!a.TileMovement.TilesWithinAttackReach().Contains(dest) && !a.UsedReaction())
                    {
                        GetComponent <AnimationTransform> ().Pause();
                        Attack opportunity = new Attack(a);
                        //TODO: give player an option to use main/offhand for reaction
                        //Hardcode offhand being false for now
                        //					IsOffhand optVal = new IsOffhand (false);
                        (opportunity.ActionOptions [0] as AttackTypeOption).chosenChoice = new AttackTypeChoice(AttackType.MAINHAND_MELEE, a.CharSheet.MainHand());
                        opportunity.IsReaction = true;
                        opportunity.LateSetTargetParameters();
                        opportunity.SetTarget(this);

                        opportunity.OnFinished += FinishedGettingOpportunityAttacked;
                        opportunity.Perform();
                    }
                }
            }
コード例 #3
0
 private void PotentialMousedOut(ATTile t)
 {
     if (OnPotentialTargetMousedOut != null)
     {
         OnPotentialTargetMousedOut(t);
     }
 }
コード例 #4
0
    void WalkingOutOfTile(string inDirection)
    {
        if (OnWalkedOutOfTile != null)
        {
            ATTile dest = null;
            ATTile now  = MapManager.instance.TileAt(avatar.position);

            switch (inDirection)
            {
            case "WalkUp":
                dest = now.Up();
                break;

            case "WalkDown":
                dest = now.Down();
                break;

            case "WalkLeft":
                dest = now.Left();
                break;

            case "WalkRight":
                dest = now.Right();
                break;
            }
            OnWalkedOutOfTile(now, dest);
        }
    }
コード例 #5
0
    public void SetOccupyingTile(ATTile from, ATTile destination)
    {
//		Debug.Log ("Setting occupaancy for " + ActorComponent.GetType());
//		Debug.Log ("Actors that sees dest: " + destination.actorsThatSeeThisTile.Count);
        if (from != null)
        {
            if (from.AllOccupants.Contains(this))
            {
                from.RemoveOccupant(this, destination);
            }
        }

        //Fixes an odd bug where this function is called after moving into a tile,
        //where the moving creature was killed by a reaction.
        //The new tile would set reachers
        if (!ActorComponent.Dying)
        {
            occupying = destination;
            CycleReachTo(destination);
            destination.AddOccupant(this, from);
        }

        if (OnTileOccupancySet != null)
        {
            OnTileOccupancySet(destination);
        }
    }
コード例 #6
0
 public void CallOnWalkedOutOfTile(ATTile current, ATTile dest)
 {
     if (OnWalkedOutOfTile != null)
     {
         OnWalkedOutOfTile(current, dest);
     }
 }
コード例 #7
0
        private void CancelMovementOnLostVision(Actor enemyLostVisionOf)
        {
            movingToPosition.canceled = true;

            lastTileLostEnemyVisionOn       = enemyLostVisionOf.TileMovement.occupying;
            enemyLostVisionOf.OnDidPerform -= CancelMovementIfEnemyActs;
        }
コード例 #8
0
    private void CheckInNow(ATTile t)
    {
        allTilesCached.Add(t);
        int tX = (int)t.transform.position.x;
        int tY = (int)t.transform.position.y;

        //		Debug.Log ("fhiL: : " + tX + " " + tY);
        if (tX < minX || minX == NOT_SET)
        {
            minX = tX;
        }

        if (tX > maxX || maxX == NOT_SET)
        {
            maxX = tX;
        }

        if (tY > maxY || maxY == NOT_SET)
        {
            maxY = tY;
        }

        if (tY < minY || minY == NOT_SET)
        {
            minY = tY;
        }
    }
コード例 #9
0
 public void EmitActorMovedEvent(Actor mover, ATTile fromTile, ATTile toTile)
 {
     if (OnActorMovedEvent != null)
     {
         ActorMovedEvent evt = new ActorMovedEvent(mover, fromTile, toTile);
         OnActorMovedEvent(evt);
     }
 }    //character event:
コード例 #10
0
 public void Reset()
 {
     if (listening)
     {
         StopListen();
     }
     chosenTile = null;
 }
コード例 #11
0
        private void TargetClicked(ATTile t)
        {
            chosenTile = t;

            if (OnTargetTileChosen != null)
            {
                OnTargetTileChosen(this);
            }
        }
コード例 #12
0
 public bool TileHasEnemyReach(ATTile t)
 {
     foreach (Actor a in t.Reachers)
     {
         if (a.EnemiesWith(this.ActorComponent) && !a.UsedReaction())
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #13
0
    //uses a* algorithm to find the shortest path from start to finish
    public List <ATTile> AStarPath(ATTile start, ATTile finish)
    {
        ATTile startNode  = start;
        ATTile targetNode = finish;

        List <ATTile> openSet   = new List <ATTile> ();
        List <ATTile> closedSet = new List <ATTile> ();

        openSet.Add(startNode);
        while (openSet.Count > 0)
        {
            ATTile currentNode = openSet [0];
            foreach (ATTile t in openSet)
            {
                if (t.FCost() < currentNode.FCost() ||
                    (t.FCost() == currentNode.FCost() && t.DistanceSquared(targetNode) < currentNode.DistanceSquared(targetNode)))
                {
                    currentNode = t;
                }
            }

            openSet.Remove(currentNode);
            closedSet.Add(currentNode);

            if (currentNode == targetNode)
            {
                return(startNode.TracePathTo(targetNode));
            }


            foreach (ATTile n in currentNode.Neighbors())
            {
                if (!n.Occupyable() || closedSet.Contains(n))
                {
                    continue;
                }

                //TODO: I think this is where a* needs to incorporate movecost of the target tile.
                int newMoveCostToNeighbor = (int)currentNode.gCost + 1;
                if (newMoveCostToNeighbor < n.gCost || !openSet.Contains(n))
                {
                    n.gCost      = newMoveCostToNeighbor;
                    n.hCost      = n.HCostTo(targetNode);
                    n.pathParent = currentNode;

                    if (!openSet.Contains(n))
                    {
                        openSet.Add(n);
                    }
                }
            }
        }
        return(null);
    }
コード例 #14
0
    public List <ATTile> TilesWithinRange(int range = -1, bool ignoreMovability = false)
    {
        List <ATTile> tiles = new List <ATTile> ();
        Actor         actor = GetComponent <Actor> ();

        if (range == -1)
        {
            range = actor.MovesLeft();
        }

        Vector3 bottomLeftOfRange = new Vector3(occupying.transform.position.x - range,
                                                occupying.transform.position.y - range);
        int checks = (range * 2) + 1;

        for (int i = 0; i < checks; i++)
        {
            for (int j = 0; j < checks; j++)
            {
                ATTile prospect = MapManager.instance.TileAt(bottomLeftOfRange + new Vector3(i, j, occupying.transform.position.z));
                if (prospect == null)
                {
                    //Debug.Log ("prospect is null");
                    continue;
                }
                if (!ignoreMovability)
                {
                    if (!prospect.Occupyable())
                    {
                        //Debug.Log ("prospect is not occupyable");
                        continue;
                    }
                    if (prospect == occupying)
                    {
                        //Debug.Log ("prospect is occ tile");
                        continue;
                    }
                    if (MapManager.instance.AStarPathForMover(actor, prospect) == null)
                    {
                        //Debug.Log ("no path to tile: " + prospect.name + ": " +  prospect.transform.position);
                        continue;
                    }
                    tiles.Add(prospect);
                }
                else
                {
                    if (prospect.HCostTo(occupying) <= range)
                    {
                        tiles.Add(prospect);
                    }
                }
            }
        }
        return(tiles);
    }
コード例 #15
0
 private void ColorTilesMousedOver(ATTile t)
 {
     cachedPath = MapManager.instance.AStarPathForMoverPreferNoReachers(actor, t);
     if (cachedPath != null)
     {
         MapManager.instance.ColorTiles(cachedPath, new Color(1f, 1f, 1f, .5f));
         List <ATTile> fromP = cachedPath.ToList();
         fromP.Insert(0, actor.GetComponent <TileMovement> ().occupying);
         DrawAOOTLines(fromP);
     }
 }
コード例 #16
0
    private void CycleReachTo(ATTile newOcc)
    {
        if (lastReachTiles != null)
        {
            RemoveReach(lastReachTiles);
        }

        List <ATTile> withinReach = TilesWithinAttackReach();

        foreach (ATTile t in withinReach)
        {
            t.AddReacher(GetComponent <Actor>());
        }

        lastReachTiles = withinReach;
    }
コード例 #17
0
    public void SetATTilePropsFromTile(Tile t, ATTile dndTile)
    {
        int moveCost = t.paramContainer.GetIntParam("baseMoveCost");

        if (moveCost != 0)
        {
            dndTile.baseMoveCost = moveCost;
        }

        bool isDiff = t.paramContainer.GetBoolParam("isDifficultTerrain");

        if (isDiff)
        {
            dndTile.IsDifficultTerrain = true;
        }
    }
コード例 #18
0
            void RadiateVision(ATTile t)
            {
                //			Debug.Log ("Radiating vision for " + GetComponent<Actor> ().GetType ());
                List <ATTile> tiles = new List <ATTile>();              //GetComponent<TileMovement> ().TilesWithinRange (VISION_DISTANCE, true);

                tiles.Add(t);

                //			Debug.Log ("from out to  " + t.transform.position + " out to "  + preCalculatedUnitCircle [0]);
                for (int i = 0; i < VISIBLE_ANGLES_OF_CASTING; i++)
                {
                    RaycastHit2D[] hits = Physics2D.RaycastAll(
                        t.transform.position + eyesOffset, preCalculatedUnitCircle [i],
                        VISION_DISTANCE,
                        MapManager.instance.TileLayerMask
                        );

                    foreach (RaycastHit2D hit in hits)
                    {
                        ATTile tileHit = hit.collider.gameObject.GetComponent <ATTile>();
                        if (!tiles.Contains(tileHit))
                        {
                            tiles.Add(tileHit);
                        }
                        if (tileHit.BlocksVision)                          // Then stop cursing over the tiles.
                        {
                            break;
                        }
                    }
                }

                RemoveVisionFrom(previousInVision, tiles);

                foreach (ATTile tile in tiles)
                {
                    if (previousInVision.Contains(tile))                      //if the previous in vision has the tile, continue
                    {
                        continue;
                    }
                    if (OnTileVisionGained != null)
                    {
                        OnTileVisionGained(tile);
                    }
                }

                previousInVision = tiles;
            }
コード例 #19
0
    //
    public virtual void Initialize()
    {
        Tilemap tm = transform.GetComponent <Tilemap> ();

        //tm.TintColor = new Color (1f,1f,1f,.75f);
//		Debug.LogError("initializing " + name);

        ForEachTile((t, x, y) => {
            ATTile tile = MapManager.instance.TileAt(x, y);
            if (tile != null)
            {
                SetATTilePropsFromTile(t, tile);
                if (overridesProperties)
                {
                    ATTile propTile = MapManager.instance.TileAt(x, y);
                    if (baseMovementCostOverride > 0)
                    {
                        //set base stuff
                        propTile.baseMoveCost = baseMovementCostOverride;
                    }

                    if (isDifficultTerrainOverride)
                    {
                        propTile.IsDifficultTerrain = true;
                    }

                    if (blocksVisionOverride)
                    {
//						Debug.Log("Setting tile blocking vision! " + x + " , " + y);
                        propTile.BlocksVision = true;
                    }

                    if (blocksMissiles)
                    {
                        propTile.BlocksMissiles = true;
                    }

                    if (unwalkableOverride)
                    {
                        propTile.overriddenAsNotWalkable = true;
                    }
                }
            }
        });
    }
コード例 #20
0
            private void NonAnimatedMovePerform(List <ATTile> thePath)
            {
                actor.GetComponent <Vision> ().OnDiscoveredByEnemy += DiscoveredByEnemyDuringNonAnimatedMove;
                List <ATTile> runningPath = thePath.ToList();

                while (runningPath.Count > 0 && !discoveryFlagged)
                {
                    ATTile nextTile = runningPath.First();

                    actor.TileMovement.CallOnWalkedOutOfTile(actor.TileMovement.occupying, nextTile);
                    actor.TileMovement.SetOccupyingTile(actor.TileMovement.occupying, nextTile);
                    actor.transform.position = nextTile.transform.position;
                    runningPath.Remove(nextTile);

//					Debug.Log ("movement left walking 1 step: " + actor.MovesLeft ());
                }

                actor.GetComponent <Vision> ().OnDiscoveredByEnemy -= DiscoveredByEnemyDuringNonAnimatedMove;
                FinishedMove();
            }
コード例 #21
0
    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Tile"))
        {
            ATTile tile = other.GetComponent <ATTile> ();
            if (tile == targetTile)
            {
                StartCoroutine(WaitForGroundZero());
            }
            else if (tile.BlocksMissiles && !this.ignoreBlockers)
            {
                if (OnHitBlocker != null)
                {
                    OnHitBlocker(this, tile);
                }
                DetachParticlesAndDestroy();
            }

            previousHitTile = tile;
        }
    }
コード例 #22
0
    public List <ATTile> AStarPathForMoverPreferNoReachers(Actor actor, ATTile finish)
    {
        List <ATTile> path = AStarPathForMover(actor, finish);

        if (path == null || path.Count == 0)
        {
            return(null);
        }

        bool TrySecond = actor.HasEnemyReachersIn(path.GetRange(0, path.Count - 1));

        if (TrySecond)
        {
            List <ATTile> path2 = AStarPathForMoverCountReachersUnwalkable(actor, finish);
            if (path2 != null && path2.Count <= path.Count)
            {
                path = path2;
            }
        }



        return(path);
    }
コード例 #23
0
        void Start()
        {
            Vision vis = GetComponent <Vision> ();

            if (vis != null)
            {
                vis.OnDiscoveredByEnemy   += GoVisibleForDiscovery;
                vis.OnUndiscoveredByEnemy += GoInvisibleForUndiscovery;
            }
            else
            {
                ATTile til = MapManager.instance.TileAt(transform.position);
                foreach (Actor a in til.actorsThatSeeThisTile)
                {
                    if (a is PlayerControlledActor)
                    {
                        GoVis();
                        break;
                    }
                }

                til.OnViewerAdded += (Actor actor) => {
                    if (actor.IsOnPlayerSide)
                    {
                        GoVis();
                    }
                };

                til.OnViewerRemoved += (Actor actor) => {
                    if (actor.IsOnPlayerSide && !til.SeenByAlliesOf(actor))
                    {
                        GoInvis();
                    }
                };
            }
        }
コード例 #24
0
    private IEnumerator DelayCheckIn(ATTile t)
    {
        yield return(new WaitForSeconds(.2f));

        CheckInNow(t);
    }
コード例 #25
0
 public void ShowSelectorOnTile(ATTile t)
 {
     selector.transform.position = t.transform.position;
     selector.GetComponent <SpriteRenderer> ().enabled = true;
 }
コード例 #26
0
        public void Initialize()
        {
            //action yielding state
            camping = new Camping(actor, this);

            //should be transitory states.... but they yield wait if somehow get caught up.
            findingBestTarget = new FindingBestTarget(actor, this);
            seekingTarget     = new SeekingTarget(actor, this);

            //more action yielding states
            movingToPosition = new MovingToPosition(actor, this);
            attacking        = new Attacking(actor, this);

            camping.AddTransition((state) => {
                return(camping.TargetSighted());
            }, findingBestTarget);

            camping.AddTransition((state) => {
                if (lastTileLostEnemyVisionOn != null)
                {
                    movingToPosition.position = lastTileLostEnemyVisionOn;
                    lastTileLostEnemyVisionOn = null;
                    return(true);
                }
                return(false);
            }, movingToPosition);

            findingBestTarget.AddTransition((state) => {
                return(findingBestTarget.NoTargetInSight());
            }, camping);
            findingBestTarget.AddTransition((state) => {
                Actor enemy = findingBestTarget.BestTarget();
                if (enemy != null)
                {
                    seekingTarget.target = enemy;
                    return(true);
                }
                return(false);
            }, seekingTarget);
            findingBestTarget.AddTransition((state) => {
                if (findingBestTarget.NoPathToBestTarget() && lastTileLostEnemyVisionOn != null)
                {
                    movingToPosition.position = lastTileLostEnemyVisionOn;
                    lastTileLostEnemyVisionOn = null;
                    return(true);
                }
                return(false);
            }, movingToPosition);


            seekingTarget.AddTransition((state) => {
                if (seekingTarget.RightByTarget())
                {
                    attacking.target = seekingTarget.target;
                    return(true);
                }
                return(false);
            }, attacking);

            seekingTarget.AddTransition((state) => {
                ATTile bestPosition = seekingTarget.BestPosition();
                if (bestPosition != null)
                {
                    movingToPosition.position = bestPosition;
                    return(true);
                }
                return(false);
            }, movingToPosition);

            seekingTarget.AddTransition((state) => {
                if (seekingTarget.NoPathToTarget())
                {
                    return(true);
                }
                return(false);
            }, findingBestTarget);



            //This cancels out the movement if any enemy characters move
            movingToPosition.OnDidEnter += (s, fromPrevious) => {
                //used to go somewhere when an enemy is seen for a flash
//				tileToInspect = null;
//				tileToInspect = null;
                foreach (Actor enemy in actor.GetComponent <Vision>().EnemiesInVision)
                {
                    enemy.OnDidPerform += CancelMovementIfEnemyActs;
                }
            };
            movingToPosition.OnWillExit += (s, toDest) => {
                foreach (Actor enemy in actor.GetComponent <Vision>().EnemiesInVision)
                {
                    enemy.OnDidPerform -= CancelMovementIfEnemyActs;
                }
            };
            movingToPosition.AddTransition((state) => {
                if (movingToPosition.ReachedPosition())
                {
                    return(true);
                }
                return(false);
            }, findingBestTarget);


            actor.GetComponent <Vision>().OnVisionOfEnemyGained += CancelMovementOnGainedVision;
            actor.GetComponent <Vision>().OnVisionOfEnemyLost   += CancelMovementOnLostVision;


            attacking.AddTransition((state) => {
                return(attacking.LostEnemySight());
            }, findingBestTarget);

            attacking.AddTransition((state) => {
                return(attacking.TargetDied());
            }, findingBestTarget);

            attacking.AddTransition((state) => {
                return(attacking.TargetMoved());
            }, findingBestTarget);

//			InitDebugStateChanges ();

            this.SwitchState(camping);
        }
コード例 #27
0
 public void TryCheckInTile(ATTile t)
 {
     StartCoroutine(DelayCheckIn(t));
     //CheckInNow (t);
 }
コード例 #28
0
 public void LaunchAt(AT.ATTile tTile, bool noBlockers = false)
 {
     targetTile = tTile;
     LaunchAt(targetTile.transform, noBlockers);
 }
コード例 #29
0
 void TellBattleManagerToEmitMoved(ATTile fromTile, ATTile toTile)
 {
     BattleManager.instance.EmitActorMovedEvent(this.ActorComponent, fromTile, toTile);
 }
コード例 #30
0
    void AvatarMovedInto(ATTile from, ATTile toDestination)
    {
        ResetRenderLayer(MapManager.instance, new Vector2(toDestination.transform.position.x, toDestination.transform.position.y));

        SetChildrenOffsets(GetComponent <SpriteRenderer>().sortingOrder);
    }