Ejemplo n.º 1
0
 public void Respawn(int x, int y)
 {
     X            = x;
     Y            = y;
     Stats.Health = Stats.HealthMax;
     IsAlive      = true;
     IsDying      = false;
     VState       = UnitVisualState.Idle;
     LinkToWorld();
     if (NetworkManager.IsServer)
     {
         Server.NotifyRespawn(this);
     }
     DoUpdateView = true;
 }
Ejemplo n.º 2
0
 protected void InitBaseUnit()
 {
     IsAlive   = true;
     IsDying   = false;
     Stats     = new UnitStats();
     CoreStats = Stats;
     ItemStats = new UnitStats();
     Actions.Clear();
     States.Clear();
     Actions.Add(new IdleAction(this));
     States.Add(new IdleState(this));
     VState       = UnitVisualState.Idle;
     DoUpdateView = true;
     ItemsBody    = new ItemPack(false, this);
     ItemsPack    = new ItemPack(false, this);
 }
Ejemplo n.º 3
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        bool bAlive = LogicUnit.IsAlive && !LogicUnit.IsDying;

        if (LogicUnit.GetVisibility() != 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            if (HpRenderer != null)
            {
                HpRenderer.enabled = false;
            }
            if (PlayerNickObject != null)
            {
                PlayerNickObject.SetActive(false);
            }
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = bAlive;
            if (HpRenderer != null)
            {
                HpRenderer.enabled = LogicUnit.IsAlive;
            }
            if (PlayerNickObject != null)
            {
                PlayerNickObject.SetActive(LogicUnit.IsAlive);
            }
            oldVisibility = true;
            return;
        }

        bool hovered = (MapView.Instance.HoveredObject == LogicUnit);

        if (Renderer != null)
        {
            Renderer.material.SetFloat("_Lightness", hovered ? 0.75f : 0.5f);
        }
        bool selected = (MapView.Instance.SelectedObject == LogicUnit);

        if (HpMat1 != null)
        {
            HpMat1.color = new Color(1, 1, 1, selected ? 1f : 0.5f);
        }
        if (HpMat2 != null)
        {
            HpMat2.color = new Color(1, 1, 1, selected ? 1f : 0.5f);
        }

        if (LogicUnit.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = bAlive;
            if (HpRenderer != null)
            {
                HpRenderer.enabled = LogicUnit.IsAlive;
            }
            if (PlayerNickObject != null)
            {
                PlayerNickObject.SetActive(LogicUnit.IsAlive);
            }

            UnitClass dCls = LogicUnit.Class;
            if (!LogicUnit.IsAlive)
            {
                while (dCls.Dying != null && dCls.Dying != dCls)
                {
                    dCls = dCls.Dying;
                }
            }

            Images.AllodsSpriteSeparate sprites = dCls.File.File;

            dCls.File.UpdateSprite();
            sprites = dCls.File.File;

            if (!spriteSet)
            {
                Renderer.material       = new Material(MainCamera.MainShaderPaletted);
                ShadowRenderer.material = Renderer.material;
                spriteSet = true;
            }

            // handle invisiblity flag
            if ((LogicUnit.Flags & UnitFlags.Invisible) != 0)
            {
                Renderer.material.color       = new Color(1, 1, 1, 0.5f);
                ShadowRenderer.material.color = new Color(0, 0, 0, 0.25f);
            }
            else
            {
                Renderer.material.color       = new Color(1, 1, 1, 1);
                ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
            }

            int actualFrame = dCls.Index; // draw frame 0 of each unit

            UnitVisualState actualVState = LogicUnit.VState;
            if (!bAlive && actualVState == UnitVisualState.Idle)
            {
                if (LogicUnit.BoneFrame == 0 || dCls.BonePhases < 3)
                {
                    actualVState         = UnitVisualState.Dying;
                    LogicUnit.DeathFrame = dCls.DyingPhases - 1;
                }
                else
                {
                    actualVState = UnitVisualState.Bone;
                }
            }

            Renderer.material.SetTexture("_Palette", GetDeathPalette(dCls.File));
            // first (idle) state is 0..8 frames. frames 1 to 7 are flipped. frames 0 and 8 aren't.
            //  135 180 225
            //  90      270
            //  45   0  315
            bool doFlip        = false;
            int  actualAngle16 = 0;
            int  actualAngle8  = 0;
            int  countFull16   = (!dCls.Flip) ? 16 : 9;
            int  countFull8    = (!dCls.Flip) ? 8 : 5;

            if (dCls.Flip)
            {
                if (LogicUnit.Angle < 180)
                {
                    actualAngle16 = LogicUnit.Angle * 8 / 180;
                    actualAngle8  = LogicUnit.Angle * 4 / 180;
                }
                else
                {
                    actualAngle16 = (180 - (LogicUnit.Angle - 180)) * 8 / 180;
                    actualAngle8  = (180 - (LogicUnit.Angle - 180)) * 4 / 180;
                    doFlip        = true;
                }
            }
            else
            {
                actualAngle16 = LogicUnit.Angle * 16 / 360;
                actualAngle8  = LogicUnit.Angle * 8 / 360;
            }

            if (actualVState == UnitVisualState.Rotating || (actualVState == UnitVisualState.Idle && dCls.IdlePhases <= 1))
            {
                actualFrame = actualAngle16;
            }
            else if (actualVState == UnitVisualState.Idle)
            {
                actualFrame  = sprites.Frames.Length - dCls.IdlePhases * countFull8 + dCls.IdlePhases * actualAngle8;
                actualFrame += dCls.IdleFrames[LogicUnit.IdleFrame].Frame;
            }
            else if (actualVState == UnitVisualState.Moving)
            {
                int moveSize = dCls.MoveBeginPhases + dCls.MovePhases;

                actualFrame  = countFull16 + moveSize * actualAngle8;
                actualFrame += dCls.MoveBeginPhases; // movebeginphases, we don't animate this yet
                actualFrame += dCls.MoveFrames[LogicUnit.MoveFrame].Frame;
            }
            else if (actualVState == UnitVisualState.Attacking)
            {
                int moveSize   = dCls.MoveBeginPhases + dCls.MovePhases;
                int attackSize = dCls.AttackPhases;

                actualFrame  = countFull16 + moveSize * countFull8 + attackSize * actualAngle8;
                actualFrame += dCls.AttackFrames[LogicUnit.AttackFrame].Frame;
            }
            else if (actualVState == UnitVisualState.Dying)
            {
                int moveSize   = dCls.MoveBeginPhases + dCls.MovePhases;
                int attackSize = dCls.AttackPhases;
                int dyingSize  = dCls.DyingPhases;

                actualFrame  = countFull16 + moveSize * countFull8 + attackSize * countFull8 + dyingSize * actualAngle8;
                actualFrame += LogicUnit.DeathFrame;
            }
            else if (actualVState == UnitVisualState.Bone)
            {
                int moveSize   = dCls.MoveBeginPhases + dCls.MovePhases;
                int attackSize = dCls.AttackPhases;
                int dyingSize  = dCls.DyingPhases;
                int boneSize   = dCls.BonePhases;

                actualFrame  = countFull16 + moveSize * countFull8 + attackSize * countFull8 + dyingSize * countFull8 + boneSize * actualAngle8;
                actualFrame += LogicUnit.BoneFrame - 1;
            }

            Vector2 xP = MapView.Instance.MapToScreenCoords(LogicUnit.X + LogicUnit.FracX + (float)LogicUnit.Width / 2,
                                                            LogicUnit.Y + LogicUnit.FracY + (float)LogicUnit.Height / 2,
                                                            1, 1);
            CurrentPoint = xP;
            float zInv = 0;
            if (!bAlive)
            {
                zInv = 48;
            }
            else if (LogicUnit.IsFlying)
            {
                zInv = -128;
            }
            transform.localPosition = new Vector3(xP.x, xP.y, MakeZFromY(xP.y) + zInv); // order sprites by y coordinate basically
            //Debug.Log(string.Format("{0} {1} {2}", xP.x, sprites.Sprites[0].rect.width, LogicUnit.Class.CenterX));
            //Renderer.sprite = sprites.Sprites[actualFrame];
            UnitMesh   = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (UnitMesh == null), doFlip);
            ShadowMesh = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null), doFlip); // 0.3 of sprite height
            UpdateHpMesh();

            LogicUnit.DoUpdateView = false;
        }
    }