Ignore:
Timestamp:
2013-07-24 23:56:47 (6 years ago)
Author:
dezhidki
Message:

Muokattu sotilaita viimeiseen muotoon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs

    r4635 r4646  
    99using Microsoft.Xna.Framework; 
    1010using CastleMaster.Entities.TileEntities; 
     11using CastleMaster.Ai.Orders; 
    1112 
    1213namespace CastleMaster.Units.Mobs 
     
    1415    public class MobWoodcutter : Mob 
    1516    { 
     17        private enum OrderType { CHOP, MOVE, AVOID, NONE } 
     18 
    1619        private TileEntityTree currentTarget; 
    17         private bool isChopping = false, isOrderedToChop = false; 
     20        private bool isChopping = false; 
    1821        private AnimationHelper choppingAnimation; 
    1922        private int currentSpriteX; 
     23        private OrderType currentOrderType = OrderType.NONE; 
     24        private int lastSameOrderAmount = 0; 
     25        private bool engangeChopping = false; 
    2026 
    2127        public MobWoodcutter(Level level, Player owner) 
     
    6369        { 
    6470            isChopping = false; 
    65             isOrderedToChop = false; 
     71            currentOrderType = OrderType.NONE; 
    6672            choppingAnimation.Stop(); 
    6773            choppingAnimation.Reset(); 
    6874        } 
    6975 
    70         public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 
     76        public override void OnFunctionClick(float x, float z, int sameOrderAmount, bool wasCalledBefore) 
    7177        { 
    72             TileEntity te = level.GetTileEntity((int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE)); 
     78            TileEntity te = level.GetTileEntity(this, (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE)); 
    7379            if (te != null && typeof(TileEntityTree).IsAssignableFrom(te.GetType())) 
    7480            { 
    7581                if (currentTarget != null) StopChopping(); 
    76                 isOrderedToChop = true; 
     82                currentOrderType = OrderType.CHOP; 
    7783                currentTarget = (TileEntityTree)te; 
    78                 SetOrder(new OrderMove(currentTarget.X, currentTarget.Z, 20.0F, true, !wasCalledBefore)); 
     84                SetOrder(new OrderMove(currentTarget.X, currentTarget.Z, 20.0F, sameOrderAmount * 4.0F, true, !wasCalledBefore)); 
    7985            } 
    8086            else 
     
    8591                    currentTarget = null; 
    8692                } 
    87                 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore)); 
     93                SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore, stopOnMoveFail: true)); 
    8894            } 
     95            lastSameOrderAmount = sameOrderAmount; 
    8996        } 
    9097 
    9198        protected override void OnOrderFinished() 
    9299        { 
    93             if (isOrderedToChop) 
     100            base.OnOrderFinished(); 
     101 
     102            if (currentOrderType == OrderType.CHOP) 
    94103                StartChopping(); 
    95104        } 
     
    101110            if (isChopping) 
    102111            { 
     112                TurnTowards(currentTarget.X, currentTarget.Z); 
    103113                choppingAnimation.UpdateStep(); 
    104114            } 
     115            else if (!isChopping && currentOrderType == OrderType.CHOP) 
     116            { 
     117                if (currentOrder != null && currentOrder is OrderMove && ((OrderMove)currentOrder).FailingToMove) 
     118                { 
     119                    StopChopping(); 
     120                    StopCurrentOrder(); 
     121                } 
     122            } 
     123 
    105124 
    106125            currentSpriteX = isChopping ? choppingAnimation.CurrentFrame : walkingAnimation.CurrentFrame; 
Note: See TracChangeset for help on using the changeset viewer.