コード例 #1
0
        public override void Update(float dt)
        {
            if (!isAttacking)
            {
                //Simple walk to player
                if (!walker.dest.HasValue || walker.dest != E.player.pos)
                {
                    walker.SetDest(E.player.pos, 1, 0);
                }

                //Is we're blocked for some time try to find a way around other mobs
                if (walker.isWalkBlocked && walker.walkBlockedTime > 0.5f) //TODO: random time?
                {
                    //log(format("%s %f", isWalkBlocked, walkBlockedTime));
                    walker.SetDest(E.player.pos, 1, 10);
                }

                //Attack
                if (!walker.isWalking && HexXY.Dist(pos, E.player.pos) == 1)
                {
                    isAttacking = true;
                    Interfacing.PerformInterfaceAttack(graphicsHandle, E.player.pos);
                    fibered.StartFiber(AttackFiber());
                }
            }

            base.Update(dt);
        }
コード例 #2
0
ファイル: AvatarFlame.cs プロジェクト: Dzugaru/hexes
        public void OnMove(HexXY from, HexXY to, bool isDrawing)
        {
            EnsurePrevMoveFinished();

            if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
            {
                avatar.finishState = Avatar.FinishedState.CantMoveThere;
                return;
            }

            if (!isDrawing)
            {
                if (!avatar.spell.caster.SpendMana(1))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }
            else
            {
                if (!avatar.spell.caster.SpendMana(5))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }

            this.isDrawing = isDrawing;

            Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
            movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar element entity changes pos
            movPos      = to;
        }
コード例 #3
0
ファイル: Entity.cs プロジェクト: Dzugaru/hexes
        public virtual void Die()
        {
            foreach (var comp in components)
            {
                comp.OnDie();
            }

            Level.S.entityList.Remove(this);
            Level.S.RemoveEntity(pos, this);
            Interfacing.PerformInterfaceDie(graphicsHandle);
        }
コード例 #4
0
 public void OnMove(HexXY from, HexXY to, bool isDrawing)
 {
     if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
     {
         avatar.finishState = Avatar.FinishedState.CantMoveThere;
     }
     else
     {
         Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
         movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar changes pos
     }
 }
コード例 #5
0
ファイル: Entity.cs プロジェクト: Dzugaru/hexes
        public virtual void UpdateInterface()
        {
            if (this is IHasHP)
            {
                Interfacing.PerformInterfaceUpdateHP(graphicsHandle, hasHP.currentHP, hasHP.maxHP);
            }

            IRotatable rotatable = this as IRotatable;

            if (rotatable != null)
            {
                if (rotatable.CanRotate)
                {
                    Interfacing.PerformInterfaceUpdateRotation(graphicsHandle, dir);
                }
            }
        }
コード例 #6
0
        IEnumerator <float> AttackFiber()
        {
            var oldPlayerPos = E.player.pos;

            yield return(attackDmgAppDelay);

            if (E.player.pos == oldPlayerPos)
            {
                //Apply dmg
                float dmg = attackDamage;
                Interfacing.PerformInterfaceDamage(E.player.graphicsHandle, dmg);
                //TODO: refresh bar including new dot speed? (same with dotheal)
            }

            yield return(attackDur - attackDmgAppDelay);

            isAttacking = false;
        }
コード例 #7
0
ファイル: Entity.cs プロジェクト: Dzugaru/hexes
        public virtual void Spawn(HexXY p)
        {
            if (!hasGraphicsHandle)
            {
                graphicsHandle = Interfacing.CreateEntity(this);
            }

            pos = p;

            Level.S.entityList.Add(this);
            Level.S.AddEntity(p, this);

            foreach (var comp in components)
            {
                comp.OnSpawn(p);
            }

            Interfacing.PerformInterfaceSpawn(graphicsHandle, pos, dir);
            UpdateInterface();
        }
コード例 #8
0
 public void Click()
 {
     //Die();
     Interfacing.ShowScrollWindow(this);
 }
コード例 #9
0
ファイル: Walker.cs プロジェクト: Dzugaru/hexes
        public bool OnUpdate(float dt)
        {
            if (onTileCenter && shouldRecalcPath)
            {
                var pathLen = Pathfinder.FindPath(entity.pos, dest.Value, pathStorage, distToStop, blockedCost);
                //Logger.Log(pathLen.ToString());
                pathStart        = 0;
                shouldRecalcPath = false;
                isWalkBlocked    = false;

                if (!pathLen.HasValue || pathLen.Value == 0)
                {
                    pathEnd = 0;
                    if (isWalking)
                    {
                        Interfacing.PerformInterfaceStop(entity.graphicsHandle, entity.pos);
                        isWalking = false;
                    }
                    return(true);
                }


                pathEnd = pathLen.Value;
            }

            if (pathStart == pathEnd)
            {
                return(true);
            }
            var nextTile = pathStorage[pathStart];

            if (distToNextTile > 0.5)
            {
                entity.pos = prevTile;
            }
            else
            {
                entity.pos = nextTile;
            }

            if (onTileCenter)
            {
                if (Level.S.GetPFBlockedMap(nextTile) == WorldBlock.PFBlockType.DynamicBlocked)
                {
                    if (!isWalkBlocked)
                    {
                        isWalkBlocked   = true;
                        walkBlockedTime = 0;
                        isWalking       = false;
                        Interfacing.PerformInterfaceStop(entity.graphicsHandle, entity.pos);
                    }
                    walkBlockedTime += dt;
                    return(true);
                }
                isWalkBlocked = false;
                Level.S.SetPFBlockedMap(nextTile, WorldBlock.PFBlockType.DynamicBlocked);
                Level.S.SetPFBlockedMap(prevTile, WorldBlock.PFBlockType.Unblocked);
                pfBlockedTile = nextTile;

                Interfacing.PerformInterfaceMove(entity.graphicsHandle, nextTile, distToNextTile * invSpeed);
                isWalking = true;
            }

            float timeLeft = distToNextTile * invSpeed;

            if (timeLeft > dt)
            {
                distToNextTile -= dt * speed;
                onTileCenter    = false;
            }
            else
            {
                prevTile       = nextTile;
                distToNextTile = 1;
                onTileCenter   = true;
                ++pathStart;

                if (pathEnd - pathStart > 0)
                {
                    OnUpdate(dt - timeLeft);
                }
                else
                {
                    Interfacing.PerformInterfaceStop(entity.graphicsHandle, prevTile);
                    isWalking = false;
                }
            }

            return(true);
        }
コード例 #10
0
 public void OnRotate(uint dir)
 {
     Interfacing.PerformInterfaceUpdateRotation(graphicsHandle, dir);
 }
コード例 #11
0
ファイル: HasHP.cs プロジェクト: Dzugaru/hexes
 public void Damage(float dmg)
 {
     currentHP = Math.Max(0, currentHP - dmg);
     Interfacing.PerformInterfaceDamage(entity.graphicsHandle, dmg);
     entity.UpdateInterface();
 }
コード例 #12
0
ファイル: Player.cs プロジェクト: Dzugaru/hexes
        //Trace first straight line dest and move there
        void MovePart()
        {
            //Debug.Log("MOVEPART " + p);
            uint?pathLen = Pathfinder.FindPath(pos, dest.Value, pathStorage, distToStop, 10);

            if (pathLen.HasValue && pathLen.Value > 0)
            {
                HexXY firstPathCell = pathStorage[0];
                if (!blockedCells.Contains(firstPathCell) && Level.S.GetPFBlockedMap(firstPathCell) != WorldBlock.PFBlockType.Unblocked)
                {
                    //Even first cell is blocked, just rotate there
                    dest      = null;
                    isWalking = false;
                    Interfacing.PerformInterfaceStop(graphicsHandle, pos);
                    Interfacing.PerformInterfaceUpdateRotation(graphicsHandle, (uint)HexXY.neighbours.IndexOf(pathStorage[0] - pos));
                }
                else
                {
                    //Try to trace a line to these
                    //First line that will be blocked will determine max straight-line destination
                    //Path to first cell should not be blocked so start with second
                    if (pathLen.Value == 1)
                    {
                        interDest     = pathStorage[0];
                        interFracDest = interDest.ToPlaneCoordinates();
                    }
                    else
                    {
                        for (int i = 1; i < pathLen.Value; i++)
                        {
                            HexXY inter = pathStorage[i];

                            //Check if straight line backwards is blocked
                            Vector2 linePos       = inter.ToPlaneCoordinates();
                            Vector2 lineDir       = (fracPos - linePos).normalized;
                            bool    isLineBlocked = false;
                            HexXY   traced        = inter;

                            do
                            {
                                float minDist    = float.MaxValue;
                                float lineShift  = 0;
                                HexXY nextTraced = new HexXY(0, 0);
                                for (int n = 0; n < 6; n++)
                                {
                                    HexXY   np      = traced + HexXY.neighbours[n];
                                    Vector2 v       = np.ToPlaneCoordinates() - linePos;
                                    float   lineLen = Vector2.Dot(v, lineDir);
                                    if (lineLen < 0)
                                    {
                                        continue;
                                    }
                                    float dist = (lineDir * lineLen - v).magnitude;
                                    if (dist < 0.8f) //Line intersects cell np (circle approximated, not hexagon though, and larger (should be less than cos(60)) so it will not cut walls)
                                    {
                                        if (!blockedCells.Contains(np) && Level.S.GetPFBlockedMap(np) != WorldBlock.PFBlockType.Unblocked)
                                        {
                                            isLineBlocked = true;
                                            break;
                                        }

                                        if (dist < minDist)
                                        {
                                            minDist    = dist;
                                            nextTraced = np;
                                            lineShift  = lineLen;
                                        }
                                    }
                                }

                                traced   = nextTraced;
                                linePos += lineShift * lineDir;
                            } while (!isLineBlocked && traced != pos);

                            if (isLineBlocked) //Choose the previous cell
                            {
                                interDest     = pathStorage[i - 1];
                                interFracDest = interDest.ToPlaneCoordinates();
                                break;
                            }

                            //Got to the last cell - use it
                            if (i == pathLen.Value - 1)
                            {
                                interDest     = inter;
                                interFracDest = interDest.ToPlaneCoordinates();
                            }
                        }
                    }

                    float timeToGetThere = (fracPos - interFracDest).magnitude / speed;
                    Interfacing.PerformInterfaceMovePrecise(graphicsHandle, interFracDest, timeToGetThere);
                    isWalking = true;
                }
            }
            else
            {
                dest      = null;
                isWalking = false;
                Interfacing.PerformInterfaceStop(graphicsHandle, pos);
            }
        }
コード例 #13
0
ファイル: Player.cs プロジェクト: Dzugaru/hexes
        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);
        }