Example #1
0
        private void CreateItemFromItemDrop(IEventArgs fr, Vector3 p, ItemDrop drop, string realName)
        {
            FreeMoveEntity en = fr.GameContext.freeMove.CreateEntity();

            en.AddEntityKey(new EntityKey(fr.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
            en.AddPosition();
            en.position.Value = new Vector3(p.x, p.y, p.z);

            en.AddFreeData(FreeUtil.ReplaceVar(name, fr), null);
            en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, 1000);
            if (type == 1)
            {
                en.freeData.Cat = FreeEntityConstant.DeadBox;
            }
            else if (type == 2)
            {
                en.freeData.Cat = FreeEntityConstant.DropBox;
            }

            en.AddFlagImmutability(fr.GameContext.session.currentTimeObject.CurrentTime);

            SimpleItemInfo info = new SimpleItemInfo(realName, drop.cat, drop.id, drop.count, en.entityKey.Value.EntityId);

            en.freeData.Value = SingletonManager.Get <DeadBoxParser>().ToString(info);

            en.isFlagSyncNonSelf = true;
        }
        public override void DoAction(IEventArgs args)
        {
            FreeMoveEntity en = args.GameContext.freeMove.CreateEntity();

            en.AddEntityKey(new EntityKey(args.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
            if (pos == null)
            {
                en.AddPosition();
                en.position.Value = new Vector3(FreeUtil.ReplaceFloat(x, args), FreeUtil.ReplaceFloat(y, args),
                                                FreeUtil.ReplaceFloat(z, args));
            }
            else
            {
                UnitPosition up = pos.Select(args);
                en.AddPosition();
                en.position.Value = new Vector3(up.GetX(), up.GetY(), up.GetZ());
            }

            string realCat = FreeUtil.ReplaceVar(cat, args);

            if (realCat == null)
            {
                realCat = "";
            }
            string realValue = FreeUtil.ReplaceVar(value, args);

            if (realValue == null)
            {
                realValue = "";
            }
            en.AddFreeData(FreeUtil.ReplaceVar(key, args), null);
            en.freeData.Cat      = realCat;
            en.freeData.Value    = realValue;
            en.isFlagSyncNonSelf = true;

            en.AddFlagImmutability(args.GameContext.session.currentTimeObject.CurrentTime);

            if (distance > 0)
            {
                en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, distance);
            }

            if (!string.IsNullOrEmpty(lifeTime))
            {
                en.AddLifeTime(DateTime.Now, FreeUtil.ReplaceInt(lifeTime, args));
            }
        }
        private int CreateItemFromInventory(IEventArgs fr, FreeData fd, ItemInventory ii, Vector3 p, string realName, int entityId)
        {
            int itemAdded = 0;

            if (ii != null && ii.name != ChickenConstant.BagGround)
            {
                foreach (ItemPosition ip in ii.GetItems())
                {
                    FreeMoveEntity en = fr.GameContext.freeMove.CreateEntity();
                    en.AddEntityKey(new EntityKey(fr.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
                    en.AddPosition();
                    en.position.Value = new Vector3(p.x, p.y, p.z);

                    en.AddFreeData(FreeUtil.ReplaceVar(name, fr), null);
                    en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, 1000);
                    en.freeData.Cat = FreeEntityConstant.DeadBox;

                    FreeItemInfo itemInfo = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey());

                    if (itemInfo.cat == (int)ECategory.Weapon)
                    {
                        int key = CarryClipUtil.GetWeaponKey(ii.name, fd);
                        if (key >= 1 && key <= 3)
                        {
                            CarryClipUtil.AddCurrentClipToBag(key, fd, fr);
                        }
                    }

                    en.AddFlagImmutability(fr.GameContext.session.currentTimeObject.CurrentTime);

                    SimpleItemInfo info = new SimpleItemInfo(realName, itemInfo.cat, itemInfo.id, ip.GetCount(), en.entityKey.Value.EntityId);
                    en.freeData.Value    = SingletonManager.Get <DeadBoxParser>().ToString(info);
                    en.freeData.IntValue = entityId;

                    en.isFlagSyncNonSelf = true;

                    itemAdded++;
                }
            }

            return(itemAdded);
        }
        public override void DoAction(IEventArgs args)
        {
            FreeMoveEntity en = args.GameContext.freeMove.CreateEntity();

            en.AddEntityKey(new EntityKey(args.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
            en.AddPosition();
            en.AddFreeData(FreeUtil.ReplaceVar(name, args), new FreeEntityData(en));
            en.freeData.Cat    = "";
            en.freeData.Value  = "";
            en.freeData.ScaleX = 1f;
            en.freeData.ScaleY = 1f;
            en.freeData.ScaleZ = 1f;

            if (distance > 0)
            {
                en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, distance);
            }

            en.isFlagSyncNonSelf = true;

            FreeEntityData entityData = (FreeEntityData)en.freeData.FreeData;

            entityData.move             = (IFreeMove)SerializeUtil.Clone(move);
            entityData.createAction     = createAction;
            entityData.action           = action;
            entityData.name             = FreeUtil.ReplaceVar(name, args);
            entityData.condition        = condition;
            entityData.removeAction     = removeAction;
            entityData.effect           = (FreeEffectCreateAction)SerializeUtil.Clone(effect);
            entityData.width            = width;
            entityData.length           = length;
            entityData.height           = height;
            entityData.deadAction       = deadAction;
            entityData.damageAction     = damageAction;
            entityData.frameAction      = (IGameAction)SerializeUtil.Clone(frameAction);
            entityData.removeCondition  = removeCondition;
            entityData.removedCondition = removedCondition;
            entityData.hp = hp;

            if (width > 0 && height > 0 && length > 0)
            {
                AssetInfo info = GetAssetInfo(args, effect);
                if (!string.IsNullOrEmpty(info.AssetName))
                {
                    args.GameContext.session.commonSession.AssetManager.LoadAssetAsync(
                        entityData, info, SetGameObject);
                }
            }

            if (skills != null)
            {
                entityData.skills = new List <ISkill>();
                foreach (ISkill skill in skills)
                {
                    entityData.skills.Add((ISkill)SerializeUtil.Clone(skill));
                }
            }

            FreeData fd = GetPlayer(args);

            if (fd != null)
            {
                args.TempUse("creator", fd);
            }

            entityData.Start(args);

            if (fd != null)
            {
                args.Resume("creator");
            }
        }