Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
 protected new void Start()
 {
     ActorCustomDepthShift = (int)ZDGameRule.WorldToUnit(transform.position).x % 2 == 0 ?
                             -1e-5f :1e-5f;
     base.Start();
     animator    = GetComponent <Animator>();
     audioSource = GetComponent <AudioSource>();
     ZDAudioSource.SetupAudioSource(audioSource);
     //StartCoroutine(PauseAndPlay());
 }
Ejemplo n.º 3
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);
            }
        }
    }
Ejemplo n.º 4
0
        static public void RevisePosition(ZDObject Caller)
        {
            Vector3 UnitLoc = ZDGameRule.WorldToUnit(Caller.transform.position);

            if (Mathf.Abs(UnitLoc.x) > ZDGameRule.MAP_WIDTH_UNIT / 2)
            {
                UnitLoc.x = (UnitLoc.x > 0 ? 1 : -1) * ZDGameRule.MAP_WIDTH_UNIT / 2;
            }
            if (Mathf.Abs(UnitLoc.y) > ZDGameRule.MAP_HEIGHT_UNIT / 2)
            {
                UnitLoc.y = (UnitLoc.y > 0 ? 1 : -1) * ZDGameRule.MAP_HEIGHT_UNIT / 2;
            }
            Caller.transform.position = ZDGameRule.UnitToWorld(UnitLoc);
        }
Ejemplo n.º 5
0
    IEnumerator CreateThunder()
    {
        int i = Random.Range(10, 15);
        int x, y;

        while (i > 0)
        {
            --i;
            yield return(new WaitForSeconds(Random.Range(0.05f, 0.2f)));

            do
            {
                x = Random.Range(-RusoAttackRRangeWidth, RusoAttackRRangeWidth + 1);
                y = Random.Range(-RusoAttackRRangeHeight, RusoAttackRRangeHeight + 1);
            } while (x == 0 && x == y);
            Vector2 UnitPos = (Vector2)ZDGameRule.WorldToUnit(transform.position) + new Vector2(x, y);
            photonView.RPC("CreateAttackREffect", RpcTarget.All, UnitPos);
        }
    }
Ejemplo n.º 6
0
        protected void Update()
        {
            if (transform.hasChanged)
            {
                if (ZDMap.UpdateLocation(this))
                {
                    //Update Z axis to correct the in block layers.
                    SetActorDepth();

                    Vector3 NewUnitLocation = ZDGameRule.WorldToUnit(transform.position);

                    LocationChanged?.Invoke(this, new LocationChangeArgs(new Vector2Int((int)NewUnitLocation.x, (int)NewUnitLocation.y)));

                    if (InShelter != (ZDMap.HitAtObject(this, EObjectType.Shelter) != null))
                    {
                        InShelter = !InShelter;
                        ShelterStateChanged?.Invoke(this, new ShelterStateChangeArgs(InShelter));
                    }
                }
                transform.hasChanged = false;
            }
        }
Ejemplo n.º 7
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);
            }
        }
    }
Ejemplo n.º 8
0
    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
            }
        }
    }
Ejemplo n.º 9
0
 static public (uint, uint) WorldToMap(float x, float y)
 {
     return(UnitToMap(ZDGameRule.WorldToUnit(x, y, 0)));
 }