コード例 #1
0
    Vector2 GetValidDest(Vector2 Destination)
    {
        Vector2 PosInUnit = ZDGameRule.WorldToUnit(transform.position);
        Vector2 DesInUnit = ZDGameRule.WorldToUnit(ZDGameRule.QuadrifyDirection(Destination, transform.position));

        for (int i = 0; i < 2; ++i)
        {
            if (!PosInUnit[i].Equals(DesInUnit[i]))
            {
                int     Delta  = (PosInUnit[i] < DesInUnit[i] ? 1 : -1);
                Vector2 CurPos = PosInUnit;

                while (true)
                {
                    //Move To Currently Checking Position.
                    CurPos[i] += Delta;
                    if (!ZDMap.IsUnitInMap(CurPos) || ZDMap.HitAtUnit(CurPos, EObjectType.Obstacle) != null)
                    {
                        //Return To Last Position.
                        CurPos[i] -= Delta;
                        return(ZDGameRule.UnitToWorld(CurPos));
                    }
                    if (CurPos[i].Equals(DesInUnit[i]))
                    {
                        break;
                    }
                }
                return(ZDGameRule.UnitToWorld(DesInUnit));
            }
        }
        return(transform.position);
    }
コード例 #2
0
    void AttackInPosition(float Damage)
    {
        Vector3         UnitPos = ZDGameRule.WorldToUnit(transform.position);
        List <ZDObject> HitList = ZDMap.HitAtUnit(UnitPos, EObjectType.ADamage);

        if (HitList != null)
        {
            foreach (var obj in HitList)
            {
                ((IADamageObject)obj).Hurt(Damage);
            }
        }
    }
コード例 #3
0
    void AttackEvent(int eventNum)
    {
        //Initial Values
        Vector2Int[] HitOffsets = { new Vector2Int(0, 0) };
        float        HitDamage  = 0;
        Vector2      HitOrigin  = ZDGameRule.WorldToUnit(transform.position);

        if (eventNum < AttackDamages.Length)
        {
            HitDamage = AttackDamages[eventNum];
        }

        if (HitOffsetsConfig != null && eventNum < HitOffsetsConfig.Length)
        {
            HitOffsets = HitOffsetsConfig[eventNum];
        }

        List <ZDObject> HitList = new List <ZDObject>();

        //Get Hitten Objects
        foreach (var offset in HitOffsets)
        {
            Vector2         HitPos    = offset + HitOrigin;
            List <ZDObject> HitResult = ZDMap.HitAtUnit(HitPos, EObjectType.ADamage);
            if (HitResult != null)
            {
                HitList.AddRange(HitResult);
            }
        }
        //Apply Damages
        if (!HitDamage.Equals(0))
        {
            foreach (var obj in HitList)
            {
                ((IADamageObject)obj).Hurt(HitDamage);
            }
        }
    }
コード例 #4
0
ファイル: ZDController.cs プロジェクト: ODD2/ZoneDepict
    void Update()
    {
        if (ZDGameManager.GetGameState() == ZDGameState.Play)
        {
            if (IsPhoneTest)
            {
                #region Touch Input for Single Touch
                if (Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                {
                    if (BagClass.GetFrameBlock())
                    {
                        BagClass.SetBlockFrame(false);
                        return;
                    }

                    Touch TouchTemp = Input.GetTouch(0);

                    // TouchPos is world Position
                    Vector2 TouchPos = Camera.main.ScreenToWorldPoint(TouchTemp.position);
                    // UnitTouchPos is Unit Position
                    Vector2 UnitTouchPos = ZDGameRule.WorldToUnit(TouchPos);
                    Vector2 CharactorPos = new Vector2(TargetCharacter.transform.position.x, TargetCharacter.transform.position.y);

                    List <ZDObject> HitObjects;
                    if (IsMovingCharacter)
                    {
                        Vector2 Direction = TouchPos - CharactorPos;
                        float   Degree    = ZDGameRule.QuadAngle(Direction);
                        Vector3 Distance  = ZDGameRule.WorldToUnit(TouchPos) - ZDGameRule.WorldToUnit(CharactorPos);
                        ZDUIClass.SetMoveIndicator(TargetCharacter.transform.position, Degree, Distance.magnitude);
                    }
                    if (TouchTemp.phase == TouchPhase.Began)
                    {
                        if ((TouchPos - (Vector2)TargetCharacter.transform.position).magnitude < ZDGameRule.UNIT_IN_WORLD * ClickOnFix)
                        {
                            IsMovingCharacter = true;
                            return;
                        }
                        else if ((HitObjects = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.ACollect)) != null)
                        {
                            List <ZDObject> HitCharacter = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.Character);
                            if (HitCharacter != null)
                            {
                                return;
                            }
                            foreach (var obj in HitObjects)
                            {
                                if (obj is IACollectObject)
                                {
                                    if (TargetCharacter.GetInventory().Count < TargetCharacter.GetInventoryMax())
                                    {
                                        ((IACollectObject)obj).Collect(TargetCharacter);
                                        IsCollectItem = true;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            return;
                        }
                        else
                        {
                            // Activate Attack System
                            IsMovingCharacter = false;
                            if ((HitObjects = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.ACollect)) == null && !BagClass.GetHover())
                            {
                                IsSelectingAttack = true;
                                TouchPosRecord    = TouchPos;
                            }
                        }
                    }
                    else if (TouchTemp.phase == TouchPhase.Moved || TouchTemp.phase == TouchPhase.Stationary)
                    {
                        IsDidMovePhase = true;
                    }
                    else if (TouchTemp.phase == TouchPhase.Ended)
                    {
                        ZDUIClass.CancelMoveIndicator();
                        if (IsCollectItem)
                        {
                            IsCollectItem = false;
                            return;
                        }
                        // DoMove
                        if ((TouchTemp.deltaPosition.magnitude >= TouchMoveFix) && IsDidMovePhase)
                        {
                            IsTouchMove = true;
                        }
                        else
                        {
                            IsTouchMove = false;
                        }

                        if (IsMovingCharacter && IsTouchMove)
                        {
                            TargetCharacter.InputSprint(TouchPos);
                            IsTouchMove       = false;
                            IsMovingCharacter = false;
                            IsDidMovePhase    = false;
                            return;
                        }
                        else if (IsSelectingAttack)
                        {
                            IsSelectingAttack = false;
                            Vector2 TouchDelta = TouchPos - TouchPosRecord;
                            // Tap Normal Attack or Slide Skill Attack
                            if (TouchDelta.magnitude < TapOrSlide) // This Distance is to judge how is "Tap"
                            {
                                TargetCharacter.InputAttack(TouchPos - (Vector2)TargetCharacter.transform.position, EAttackType.N);
                            }
                            else
                            {
                                TargetCharacter.InputAttack(TouchDelta, EAttackType.Skill);
                            }
                        }
                    }
                }

                #endregion
            }
        }
    }