Пример #1
0
        public MovePath Move(IPacket packet)
        {
            var path = new MovePath(packet);

            path.Apply(this);
            return(path);
        }
 // Visualization of the path of the unit
 public void OnDrawGizmos()
 {
     if (MovePath != null)
     {
         MovePath.DrawWithGizmos();
     }
 }
Пример #3
0
    //判断移动范围-- AI控制 --2.通过地形进一步缩小移动范围
    public void JudgeMove(Vector3 pos, int mobility, GameObject Com, GameObject player)
    {
        GameObject CurrentRole = CheckObject_Move.TestRole(pos);

        if (CurrentRole != null && CurrentRole == player)
        {
            map[-(int)pos.y, (int)pos.x] = 0;
        }
        GameObject CurrentMap = CheckObject_Move.TestMap(pos);

        if (CurrentMap != null)
        {
            if (CurrentMap.GetComponent <Terrains>().CanMove)
            {
                int EndX   = -(int)pos.y;
                int EndY   = (int)pos.x;
                int StartX = -(int)Com.transform.position.y;
                int StartY = (int)Com.transform.position.x;
                if (DisplayMoveRange(map, StartX, StartY, EndX, EndY, mobility))
                {
                    MovePath point = new MovePath(EndX, EndY);
                    AiCanMovePath.Add(point);
                }
            }
        }
    }
Пример #4
0
    IEnumerator animateMove(MovePath path)
    {
        Transform img = transform.Find("img");

        while (!path.last)
        {
            HexTile target = path.next;
            Vector2 start  = transform.position;
            Vector2 end    = target.transform.position;
            if (end.x - start.x > 0)
            {
                img.localScale = new Vector3(-1, 1, 1);
            }
            else
            {
                img.localScale = new Vector3(1, 1, 1);
            }
            moveAnimationStart = Time.time;
            float t = 0;
            while (t < 1)
            {
                t += moveAnimationSpeed * Time.deltaTime;
                if (t > 0.5f && currentTile != target)
                {
                    _currentTile = target;
                }
                transform.position = Vector2.Lerp(start, end, t);
                GetComponent <RenderHeight>().RenderAt(transform);
                yield return(null);
            }
        }
        SetPosition(path.end);
        CombatManager.UpdateBoardState();
    }
Пример #5
0
    public static MovePath Clone(MovePath path)
    {
        MovePath newPath = new MovePath();

        newPath._path.AddRange(path._path);
        return(newPath);
    }
Пример #6
0
    //判断移动范围-- 玩家控制 --2.通过地形进一步缩小移动范围
    public void JudgeMove(Vector3 pos, int mobility)
    {
        GameObject CurrentRole = CheckObject_Move.TestRole(pos);

        if (CurrentRole != null)
        {
            //设置为0就不可行走
            map[-(int)pos.y, (int)pos.x] = 0;
            return;
        }

        GameObject CurrentMap = CheckObject_Move.TestMap(pos);

        if (CurrentMap != null)
        {
            if (CurrentMap.GetComponent <Terrains>().CanMove)
            {
                int EndX = -(int)pos.y;
                int EndY = (int)pos.x;

                int StartX = -(int)transform.position.y;
                int StartY = (int)transform.position.x;

                if (DisplayMoveRange(map, StartX, StartY, EndX, EndY, mobility))
                {
                    CurrentMap.transform.GetChild(0).GetComponent <SpriteRenderer>().color = new Color(0, 180, 255, 0.5f);
                    MovePath point = new MovePath(EndX, EndY);
                    path.Add(point);
                }
            }
        }
    }
Пример #7
0
    private bool handleHomeMovement(
        BoardPiece piece,
        PieceMovementData movementData,
        ref List <MovePath> result)
    {
        if (piece.boardPosition.type != PositionType.HOME)
        {
            return(false);
        }

        int  ownerIndex       = piece.ownerIndex;
        bool startingPegValid = true;

        BoardPosition startingPeg = _board.GetStartingPosition(ownerIndex);

        BoardPiece blockingPiece;

        if (_board.IsPositionOccupied(startingPeg, out blockingPiece))
        {
            startingPegValid = !blockingPiece.justLeftHome;
        }

        if (startingPegValid)
        {
            MovePath path = new MovePath();
            path.Add(startingPeg);
            result.Add(path);
        }

        return(result.Count > 0);
    }
Пример #8
0
    public bool GetPieceHitList(MovePath path, bool isSplitStomp, ref List <BoardPiece> hitList)
    {
        BoardPosition pos;
        BoardPiece    victim;

        // Eat everything in the path V--V
        if (isSplitStomp)
        {
            path.Reset();
            while (path.GetNext(out pos))
            {
                if (_board.IsPositionOccupied(pos, out victim))
                {
                    hitList.Add(victim);
                }
            }
        }
        else // Only eat last victim in path V--V
        {
            pos = path.end;
            if (_board.IsPositionOccupied(pos, out victim))
            {
                hitList.Add(victim);
            }
        }
        return(hitList.Count > 0);
    }
Пример #9
0
 // Use this for initialization
 void Start()
 {
     _move      = GetComponent <MovePath>();
     _shadowMgr = GetComponent <GhostShadowMgr>();
     _shadowMgr.Init();
     StartCoroutine(ProcessCtrl());
 }
Пример #10
0
    //3.26
    public void parallelNodeOperating(int from, int to, int thres)
    {
        if (people_toward[to].Count > people_toward[from].Count)
        {
            int tmp = to;
            to   = from;
            from = tmp;
        }

        int transCNT = (people_toward[from].Count - people_toward[to].Count) / 2;

        for (int i = 0; i < transCNT; i++)
        {
            int      cnt = (int)Random.Range(0, people_toward[from].Count - 0.00001f);
            MovePath mvp = (MovePath)people_toward[from][cnt];
            //如果太靠近from则到to的下一个点
            if (Vector3.Distance(mvp.transform.position, mvp.finishPos) <= 2.0f)
            {
                to = result[to, 2];
            }

            people_toward[from].Remove(mvp);
            people_toward[to].Insert(people_toward[to].Count, mvp);
            mvp.targetPoint = to;
            mvp.finishPos   = getNextPoint(mvp.w, mvp.targetPoint);
            mvp.finishPos.y = mvp.hit.point.y;
        }
    }
 int O = 0;      //复杂度累计(超过3个点之后不计算.计算个蛋球).
 void CalculatePath(MovePath path, Vector3 start, Vector3 end)
 {
     if (O > 3)
     {
         return;
     }
     O++;
     collider.enabled = false;
     if (Physics.SphereCast(new Ray(start, end - start), radius, out hit, GetDistace(start, end)))
     {
         if (hit.collider.bounds.Contains(end))
         {
             collider.enabled = true;
             return;
         }
         path.Insert(path.pathNode.Length - 1, GetPoit(path, hit, end - start));                                //插入倒数第二个位置一个计算好的点
         CalculatePath(path, path.pathNode[path.pathNode.Length - 2], path.pathNode[path.pathNode.Length - 1]); //计算下一个点,直到没有障碍物
     }
     else
     {
         for (int i = 0; i < path.pathNode.Length - 1; i++)
         {
             if (!Physics.Raycast(path.pathNode[i], path.pathNode[path.pathNode.Length - 1] - path.pathNode[i], GetDistace(path.pathNode[i], path.pathNode[path.pathNode.Length - 1])))
             {
                 path.RemoveToEnd(i + 1);
                 break;
             }
         }
     }
     collider.enabled = true;
 }
Пример #12
0
        public override void Apply(MovePath path)
        {
            base.Apply(path);

            path.Position   = _position;
            path.FootholdID = _footholdID;
        }
    public int radius;              //自身所占范围半径
    void Start()
    {
        radius = GetComponent <BaseElement>().boundOfMove;
        GameObject tmp_assistant = new GameObject("AssistantPath" + name);

        tmp_assistant.transform.parent = transform;
        assistantPath = tmp_assistant.AddComponent <MovePath>();
    }
Пример #14
0
    public static Projectile Create(string prefab, Vector3 pos, MovePath mp, int dmg = 0, float t = -1, bool p = false)
    {
        Projectile projectile = (Instantiate((GameObject)Resources.Load(prefab), pos, Quaternion.identity, ProjectilePool.SharedInstance.transform) as GameObject).GetComponent <Projectile>();

        projectile.name = prefab.Substring(prefab.LastIndexOf("/") + 1); //optimize?
        projectile.setValues(pos, mp, dmg, t, p);
        return(projectile);
    }
Пример #15
0
 public void setValues(Vector3 pos, MovePath mp, int dmg, float t, bool p)
 {
     spawnPos       = pos;
     trans.position = pos;
     path           = mp;
     damage         = dmg;
     destroyTime    = t;
     isPiercing     = p;
 }
Пример #16
0
 public ValidBoardMove(string coordinatesFrom, string coordinatesTo, MovePath movepath, bool isWhite) : this(coordinatesFrom, coordinatesTo, movepath)
 {
     this.IsWhite         = isWhite;
     this.CoordinatesTo   = coordinatesTo;
     this.CoordinatesFrom = coordinatesFrom;
     this.Path            = movepath;
     this.IsPinningMove   = false;
     this.MoveProperties  = new ValidNotationProperties();
 }
Пример #17
0
        public static void SendPlayerMove(Character chr, MovePath movePath)
        {
            Packet pw = new Packet(ServerMessages.MOVE_PLAYER);

            pw.WriteInt(chr.ID);
            movePath.EncodeToPacket(pw);

            chr.Field.SendPacket(chr, pw, chr);
        }
Пример #18
0
        public static void SendMovePet(Character chr, MovePath movePath)
        {
            var pw = new Packet(ServerMessages.PET_MOVE);

            pw.WriteInt(chr.ID);
            movePath.EncodeToPacket(pw);

            chr.Field.SendPacket(chr, pw, chr);
        }
Пример #19
0
 public void FollowPath(MovePath path)
 {
     moveTargeter.FindSelectable();
     Debug.Assert(path.start == currentTile);
     if (path.end != currentTile)
     {
         currentTile.occupant = null;
         StartCoroutine(animateMove(path));
     }
 }
Пример #20
0
        private static void SendMoveSummon(Character chr, Summon summon, MovePath movePath)
        {
            Packet pw = new Packet(ServerMessages.SPAWN_MOVE);

            pw.WriteInt(chr.ID);
            pw.WriteInt(summon.SkillId);
            movePath.EncodeToPacket(pw);

            chr.Field.SendPacket(pw, chr);
        }
Пример #21
0
        public virtual void SubMoveToTile(int passedCount, int stepID)
        {
            //Debug.Log("pass: "******", step: " + stepID);
            Location[] subPath = MovePath.Skip(passedCount).Take(stepID + 1).ToArray();
            //Debug.Log("mov: " + MovePath.Length + ", sub: " + subPath.Length);

            Loc.GetTileController().OnEntityLeaving();
            Loc = subPath[stepID];
            Loc.GetTileController().OnEntityEntering(Hash);

            AnimationManager.Instance.AddAnimClip(new MovePathAnimClip(Hash, subPath, 0.2f));
        }
 void OnDrawGizmos()
 {
     if (mainPath == null)
     {
         //animation.cullingType = AnimationCullingType.BasedOnRenderers;
         //AnimationCurve t = new AnimationCurve();
         //t.keys[0].time = .3f;
         GameObject pathMain = new GameObject("MainPath_" + name);
         pathMain.transform.parent = transform;
         mainPath = pathMain.AddComponent <MovePath>();
     }
 }
Пример #23
0
        public void Execute(Entity entity, int index, [ReadOnly] ref UnitSelected c0, ref CalculateMove calculateMove)
        {
            //This is acting up, time to implement solution number two, which is to add the pathbuffer to the entity, but should be done in unit creation and then populated here, because commandbuffers!
            currentEntity[0] = entity;
            MovePath movePath = new MovePath
            {
                moveSpeed      = 5f,
                positionInMove = pathLength - 1
            };

            commandBuffer.AddComponent(index, entity, movePath);
            commandBuffer.RemoveComponent(index, entity, calculateMoveType);
        }
Пример #24
0
 public override ICommand ChooseTarget(HexTile tile, bool preview)
 {
     Show(false);
     if (tile.selectable)
     {
         _path = new MovePath(Map.current.TileAt(_source), tile);
         Show(preview);
         return(new MoveCommand(_unit, _path));
     }
     else
     {
         return(null);
     }
 }
Пример #25
0
    // ctor
    public MissileDataModel(Vector3 velocity, Vector3 acceleration,
                            float friction, float collisionDistSqrt, float damage,
                            Rect validArea,
                            MovePath path = null)
    {
        this.Velocity              = velocity;
        this.Acceleration          = acceleration;
        this.Friction              = friction;
        this.CollisionDistanceSqrt = collisionDistSqrt;
        this.Damage    = damage;
        this.ValidArea = validArea;

        this.Path = path;
    }
Пример #26
0
    public void cacheAll()
    {
        straightShot = (float t, Vector3 pos) => new Vector3(pos.x, pos.y + t * 25, pos.z);

        bombPath = new MovePath[5][];
        for (int i = 0; i < bombPath.Length; i++)
        {
            bombPath[i] = new MovePath[16];
            for (int j = 0; j < bombPath[i].Length; j++)
            {
                int spd = i > 2 ? 2 : 5;
                bombPath[i][j] = bombLine(j, bombPath[i].Length, spd);
            }
        }
    }
Пример #27
0
    public void MakeTile(MovePath path, string filename, int order = 1)
    {
        GameObject     gameTile  = Resources.Load("TileObject", typeof(GameObject)) as GameObject;
        GameObject     instance  = Instantiate(gameTile) as GameObject;
        SpriteRenderer pRenderer = instance.AddComponent <SpriteRenderer>();

        Sprite tile = Resources.Load(filename, typeof(Sprite)) as Sprite;

        pRenderer.sprite       = tile;
        pRenderer.sortingOrder = order;

        Vector3 pos = new Vector3(path.x * 0.64f + 0.32f, path.y * 0.64f + 0.32f, 0);

        instance.transform.position = pos;
    }
Пример #28
0
        public static void HandleSummonMove(Character chr, Packet packet)
        {
            var skillId = packet.ReadInt();

            if (chr.Summons.GetSummon(skillId, out var summon))
            {
                var movePath = new MovePath();
                movePath.DecodeFromPacket(packet, MovePath.MovementSource.Summon);
                chr.TryTraceMovement(movePath);

                PacketHelper.ValidateMovePath(summon, movePath);

                SendMoveSummon(chr, summon, movePath);
            }
        }
Пример #29
0
    /// <summary>
    /// Calculate the best position from which I can shoot to the target using the weapon
    /// First = position closest to the player
    /// Second = position closer to the target
    /// </summary>
    private Tuple <Vector2, Vector2> GetShootPositionTo(Vector2 pShootTarget, EWeaponId pWeapon)
    {
        float maxDist   = GetWeaponMaxUseDistance(pWeapon);
        float idealDist = GetWeaponIdealUseDistance(pWeapon);

        //ideal distance shouldnt be bigger. (probably not configured)
        if (idealDist > maxDist)
        {
            idealDist = maxDist;
        }

        Tuple <Vector2, Vector2> posHorizontal =
            GetShootPositions(pShootTarget, maxDist, idealDist, true,
                              GetDontHitLayer(pWeapon));
        Tuple <Vector2, Vector2> posVertical =
            GetShootPositions(pShootTarget, maxDist, idealDist, false,
                              GetDontHitLayer(pWeapon));

        //TESTING - Select the closest shoot position
        //- simple distance compare - select the closest
        const bool useSimpleDistCompare = true;

        if (useSimpleDistCompare)
        {
            if (Vector2.Distance(playerPosition, posHorizontal.Item1) < Vector2.Distance(playerPosition, posVertical.Item1))
            {
                return(posHorizontal);
            }
            else
            {
                return(posVertical);
            }
        }

        //- calculate path and compare their lengths
        //-- seems very costly, player lags
        MovePath pathHorizontal = pathFinder.GetPath(playerPosition, posHorizontal.Item1);    //, AiMovement.PATH_STEP);
        MovePath pathVertical   = pathFinder.GetPath(playerPosition, posVertical.Item1);      //, AiMovement.PATH_STEP);

        if (pathHorizontal.GetLength() < pathVertical.GetLength())
        {
            return(posHorizontal);
        }
        else
        {
            return(posVertical);
        }
    }
Пример #30
0
 void OnEnable()
 {
     movePath = target as MovePath;
     if (movePath.pathNode == null)
     {
         movePath.pathNode = new Vector3[0];
     }
     style                  = new GUIStyle();
     style.fontStyle        = FontStyle.Normal;
     style.fontSize         = 35;
     style.normal.textColor = Color.white;
     orgStyle               = opstyle;
     Debug.Log(PrefabUtility.GetPrefabType(Selection.activeGameObject));
     if (PrefabUtility.GetPrefabType(movePath) == PrefabType.PrefabInstance)
     {
         EditorUtility.DisplayDialog("警告!", "对路径做完改动之后请不要忘记[Apply],避免丢失数据!", "确定");
     }
 }