public void Collect()
 {
     SunState = eSunState.COLLECT;
     MoveComponent moveCom = this.Owner.Owner.GetComponent(typeof(MoveComponent)) as MoveComponent;
     ////Debug.WriteLine("Add SunCollectEffect");
     AddEffect(new SunCollectEffect(moveCom.Position));
 }
        public void AddSun(Vector2 position, eSunState state)
        {
            ObjectEntityGesture sun = PZObjectFactory.Instance.createSun(position, state) as ObjectEntityGesture;
            PZObjectManager.Instance.AddObject(sun);
            _gestureDispatcher.AddTarget<Tap>(sun);

            SCSServices.Instance.AudioManager.PlaySound(_soundSunCreate, false, true);
        }
 public void setState(eSunState state)
 {
     SunState = state;
     if (SunState == eSunState.JUMP)
     {
         IEffect effect = new SunRiseEffect();
         AddEffect(effect);
     }
     else if (SunState == eSunState.PLYING)
     {
         IEffect effect = new SunFlyDownEffect();
         AddEffect(effect);
     }
 }
        public override void Update(IMessage<MessageType> msg, GameTime gameTime)
        {
            if (listEffect.Count == 0 && SunState == eSunState.PLYING)
                SunState = eSunState.STAND;

            if (listEffect.Count == 0 && SunState == eSunState.COLLECT)
            {
                // Self remove sun
                (SCSServices.Instance.Game.Services.GetService(typeof(PvZSunSystem)) as PvZSunSystem).RemoveSun(this.Owner.Owner as ObjectEntityGesture);
                //PZObjectManager.Instance.RemoveObject(this.Owner.Owner.ObjectId);
                //PvZHardCurrency._gestureDispatcher.RemoveTarget<Tap>(Owner.Owner as IGestureTarget<Tap>);
            }

            // Die
            LogicComponent logicCOm = this.Owner as LogicComponent;
            if (logicCOm == null)
                throw new Exception("PL_NormalLogicBehavior: Expect Logic Component");
            if (logicCOm.Health < 0)
            {
                PZObjectManager.Instance.RemoveObject(this.Owner.Owner.ObjectId);
            }
            base.Update(msg, gameTime);
        }
        public override void Update(IMessage<MessageType> msg, GameTime gameTime)
        {
            if (listEffect.Count == 0 && SunState == eSunState.PLYING)
                SunState = eSunState.STAND;

            if (justCollect)
            {
                if (gameTime.TotalGameTime - _lastTimeSound > _timeDelaySound)
                {
                    SCSServices.Instance.AudioManager.PlaySound(_soundCollectSun, false, true);
                    _lastTimeSound = gameTime.TotalGameTime;
                }
            }
            justCollect = false;

            if (listEffect.Count == 0 && SunState == eSunState.COLLECT)
            {
                // Self remove sun
                (SCSServices.Instance.Game.Services.GetService(typeof(PvZSunSystem)) as PvZSunSystem).RemoveSun(this.Owner.Owner as ObjectEntityGesture, true);
                //PZObjectManager.Instance.RemoveObject(this.Owner.Owner.ObjectId);
                //PvZHardCurrency._gestureDispatcher.RemoveTarget<Tap>(Owner.Owner as IGestureTarget<Tap>);
            }

            if (SunState == eSunState.STAND)
            {
                this.sunTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
                if (this.sunTime <= 0)
                {
                    (SCSServices.Instance.Game.Services.GetService(typeof(PvZSunSystem)) as PvZSunSystem).RemoveSun(this.Owner.Owner as ObjectEntityGesture, false);
                }
            }

            // Die
            LogicComponent logicCOm = this.Owner as LogicComponent;
            if (logicCOm == null)
                throw new Exception("PL_NormalLogicBehavior: Expect Logic Component");
            if (logicCOm.Health < 0)
            {
                PZObjectManager.Instance.RemoveObject(this.Owner.Owner.ObjectId);
            }
            base.Update(msg, gameTime);
        }
        public ObjectEntity createSun(Vector2 vector2, eSunState state)
        {
            ObjectEntity plant = GameObjectCenter.Instance.CreateObject("xml_sun");

            MoveComponent moveCom = plant.GetComponent(typeof(MoveComponent)) as MoveComponent;
            moveCom.Position = vector2;

            LogicComponent logicCom = plant.GetComponent(typeof(LogicComponent)) as LogicComponent;

            (logicCom.LogicBehavior as B_SunLogicBehavior).setState(state);

            return plant;
        }
 public void AddSun(Vector2 position, eSunState state)
 {
     ObjectEntityGesture sun = PZObjectFactory.Instance.createSun(position, state) as ObjectEntityGesture;
     PZObjectManager.Instance.AddObject(sun);
     _gestureDispatcher.AddTarget<Tap>(sun);
 }