Пример #1
0
        public void CastAbilitySpell(int i, HexXY p)
        {
            bool isSuccess = abilitySpells[i] != null;

            if (isSuccess)
            {
                abilitySpells[i].CastMelee(this, HexXY.GetApproximateDir(pos, p), false);
            }
            else if (ActionFailure != null)
            {
                ActionFailure();
            }
        }
Пример #2
0
        public SpellExecuting CastRanged(ICaster caster, HexXY target)
        {
            var  pos  = ((Entity)caster).pos;
            var  dist = HexXY.Dist(pos, target);
            uint dir;

            if (dist == 0)
            {
                dir = ((Entity)caster).dir;
            }
            else
            {
                dir = HexXY.GetApproximateDir(pos, target);
            }


            var spEx = new SpellExecuting(caster, this, target, dir, false);

            spEx.SpawnAvatar(root, null, target, dir);
            executingSpells.Add(spEx);
            return(spEx);
        }
Пример #3
0
        void Walking(float dt)
        {
            HexXY prevPos = pos;

            float distToTargetSqr = (interFracDest - fracPos).sqrMagnitude;

            Vector2 dir = (interFracDest - fracPos).normalized;

            //Calculate blocking
            //Debug.Log(distToTargetSqr + " " + (blockForwardDist * blockForwardDist));
            if (distToTargetSqr >= blockForwardDist * blockForwardDist)
            {
                Vector2 nextBlockPos = fracPos + dir * blockForwardDist;
                HexXY   nextPosCell  = HexXY.FromPlaneCoordinates(nextBlockPos);
                if (!blockedCells.Contains(nextPosCell))
                {
                    if (Level.S.GetPFBlockedMap(nextPosCell) != WorldBlock.PFBlockType.Unblocked)
                    {
                        //Blocked by something - stop and move to nearest cell center
                        dest = interDest = pos;
                        //Debug.Log("Blocked dest " + pos);
                        interFracDest = pos.ToPlaneCoordinates();
                        float timeToGetThere = (fracPos - interFracDest).magnitude / (speed * 0.5f); //at half speed
                        Interfacing.PerformInterfaceMovePrecise(graphicsHandle, interFracDest, timeToGetThere);
                        return;
                    }
                    else
                    {
                        Level.S.SetPFBlockedMap(nextPosCell, WorldBlock.PFBlockType.DynamicBlocked);
                        //G.S.DebugShowCell(nextPosCell);
                        blockedCells.Add(nextPosCell);
                    }
                }
            }

            //Calculate movement
            Vector2 step = dir * speed * dt;

            if (step.sqrMagnitude == 0 || step.sqrMagnitude > distToTargetSqr)
            {
                fracPos = interFracDest;
                if (HexXY.Dist(interDest, dest.Value) <= distToStop)
                {
                    dest      = null;
                    isWalking = false;
                    Interfacing.PerformInterfaceStop(graphicsHandle, pos);
                }
                else
                {
                    MovePart();
                }
            }
            else
            {
                fracPos += step;
            }

            pos = HexXY.FromPlaneCoordinates(fracPos);

            if (pos != prevPos)
            {
                Level.S.RemoveEntity(prevPos, this);
                Level.S.AddEntity(pos, this);

                //Remove blocked cells that are behind us
                blockedCellsToDelete.Clear();

                foreach (var bc in blockedCells)
                {
                    Vector2 bcFrac = bc.ToPlaneCoordinates();
                    if (bc != pos && Vector2.Dot(fracPos - bcFrac, dir) > blockBackDist)
                    {
                        blockedCellsToDelete.Add(bc);
                    }
                }

                foreach (var dbc in blockedCellsToDelete)
                {
                    blockedCells.Remove(dbc);
                    Level.S.SetPFBlockedMap(dbc, WorldBlock.PFBlockType.Unblocked);
                    //G.S.DebugHideCell(dbc);
                }
            }

            this.dir = HexXY.GetApproximateDir(dir);
        }