예제 #1
0
        /// <summary>
        /// 处理生成事件
        /// </summary>
        protected void HandlerInitEvent(InitEventMessage initEvent)
        {
            if (initEvent == null)
            {
                return;
            }
            ActorBase actor = null;

            if (initEvent.haveId)
            {
                actor = levelContainer.GetCreateInternalComponentBase().CreateActor(initEvent.actortype, initEvent.camp,
                                                                                    initEvent.point_x,
                                                                                    initEvent.point_y, initEvent.angle, initEvent.actorid, initEvent.IsPlayer, initEvent.weapontype_a,
                                                                                    initEvent.weapontype_b, initEvent.name, initEvent.time);
            }
            else
            {
                actor = levelContainer.GetCreateInternalComponentBase().CreateActor(initEvent.actortype, initEvent.camp,
                                                                                    initEvent.point_x,
                                                                                    initEvent.point_y, initEvent.angle, initEvent.IsPlayer, initEvent.weapontype_a,
                                                                                    initEvent.weapontype_b, initEvent.name, initEvent.time);
                initEvent.actorid = actor.GetActorID();
            }
            if (initEvent.time != 0)
            {
                actor.SetActorInitPro(initEvent.time);
            }

            if (actor != null)
            {
                if (actor is ISkillContainer skill)
                {
                    skill.SetOwnerID(initEvent.onwerid);
                }

                actor.SetRelPosition(initEvent.relatpoint_x, initEvent.relatpoint_y);
                actor.SetLinerDamping(initEvent.LinerDamping);
                levelContainer.GetEnvirinfointernalBase().AddActor(actor);
            }
            Log.Trace("HandlerComponentBase HandlerInitEvent: 生成一个Actor id" + actor.GetActorID() + " " + actor.GetActorType());
            //执行回调生成事件
            OnInitMessageHandler?.Invoke(initEvent.actorid);
            initMessageNum++;
        }
        public void AddActor(ActorBase actor)
        {
            IBaseComponentContainer container = actor as IBaseComponentContainer;
            var init = container.GetInitData();

            //actor.CreateBody(factory.CreateRectangleBody(init.point_x, init.point_y, 10, 10));

            //判断是否是激光
            if (actor.GetActorType() != ActorTypeBaseDefine.ContinuousLaserActor && actor.GetActorType() != ActorTypeBaseDefine.PowerLaserActor)
            {
                actor.CreateBody(factory.CreateSpaceWonderBody(new Vector2(init.point_x, init.point_y), init.angle, actor.GetGameModelByActorType(), new UserData(actor.GetActorID(), actor.GetActorType())));
            }
            //是持续激光
            else if (actor.GetActorType() == ActorTypeBaseDefine.ContinuousLaserActor)
            {
                //获取长宽属性
                var WH = ActorHelper.GetLaserShapeByShip(actor.GetActorType());
                actor.CreateBody(factory.CreateSpaceWonderLaser(new Vector2(init.point_x, init.point_y), init.angle, new UserData(actor.GetActorID(), actor.GetActorType()), WH.X, WH.Y));
            }
            //是蓄力激光
            else if (actor.GetActorType() == ActorTypeBaseDefine.PowerLaserActor)
            {
                var WH = ActorHelper.GetLaserShapeByShip(actor.GetActorType(), heightpro: actor.GetActorInitPro());

                //Log.Trace("AddActor: actorID" + actor.GetActorID() + " InitDate" + init.point_x + " " + init.point_y + " " + init.angle + " WeaponDemage:" + ((IWeaponBaseComponentContainer)actor).GetWeaponDamage() + " WH" + WH.X + " " + WH.Y + " InitPro:" + actor.GetActorInitPro());

                actor.CreateBody(factory.CreateSpaceWonderLaser(new Vector2(init.point_x, init.point_y), init.angle, new UserData(actor.GetActorID(), actor.GetActorType()), WH.X, WH.Y));
            }
            //Log.Trace("AddActor: actorID" + actor.GetActorID() + " InitDate" + init.point_x + " " + init.point_y + " " + init.angle);
            //Log.Trace("actor id" + actor.GetActorID() + " 生成一个Actor Position:" + actor.GetPosition() + " Forward:" + actor.GetForward());

            _actorList.Add(actor);
        }
예제 #3
0
        /// <summary>
        /// 处理销毁事件
        /// </summary>
        protected void HandlerDestroyEvent(DestroyEventMessage destroyEvent)
        {
            if (destroyEvent == null)
            {
                return;
            }
            //Log.Trace("处理销毁事件" + destroyEvent.actorid);

            //先执行回调销毁事件
            OnDestroyMessageHandler?.Invoke(destroyEvent.actorid);
            ActorBase actor = null;

            if (levelContainer == null)
            {
                return;
            }
            if (levelContainer.GetEnvirinfointernalBase() == null)
            {
                return;
            }
            if (levelContainer.GetEnvirinfointernalBase().GetAllActors() == null)
            {
                return;
            }
            foreach (var actorBase in levelContainer.GetEnvirinfointernalBase().GetAllActors())
            {
                if (actorBase.GetActorID() == destroyEvent.actorid)
                {
                    actor = actorBase;
                }
            }
            if (actor == null)
            {
                return;
            }
            if (actor.IsPlayer() && actor.IsShip())
            {
                string i       = null;
                var    players = levelContainer.GetPlayerDict();
                foreach (var p in players)
                {
                    if (p.Value == actor.GetActorID())
                    {
                        i = p.Key;
                    }
                }
                if (i != null)
                {
                    players.Remove(i);
                }
                if (players.Count == 0)
                {
                    levelContainer.AddEventMessagesToHandlerForward(new FailEventMessage(levelContainer.GetLevelID()));
                }
            }
            levelContainer.GetEnvirinfointernalBase().RemoveActor(actor);
            actor.Dispose();


            DestoryMessageNum++;
        }