Ejemplo n.º 1
0
        public void RemoveObject(VMEntity obj)
        {
            var             guid = obj.Object.OBJ.GUID;
            List <VMEntity> list = null;

            ObjectsByGUID.TryGetValue(guid, out list);
            if (list != null)
            {
                VM.DeleteFromObjList(list, obj);
                if (list.Count == 0)
                {
                    ObjectsByGUID.Remove(guid);
                }
            }
            RemoveCategory(obj, obj.GetValue(VMStackObjectVariable.Category));

            if (obj is VMAvatar)
            {
                Avatars.Remove(obj);
                AvatarsByPersist.Remove(obj.PersistID);
            }
            else if (obj.PersistID > 0 && obj.MultitileGroup.Objects.Count == 1)
            {
                MultitileByPersist.Remove(obj.PersistID);
                if (obj.Thread != null)
                {
                    var vm = obj.Thread.Context.VM;
                    if (vm.PlatformState.LimitExceeded)
                    {
                        VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void NewObject(VMEntity obj)
        {
            var             guid = obj.Object.OBJ.GUID;
            List <VMEntity> list = null;

            ObjectsByGUID.TryGetValue(guid, out list);
            if (list == null)
            {
                list = new List <VMEntity>();
                ObjectsByGUID.Add(guid, list);
            }
            VM.AddToObjList(list, obj);
            RegisterCategory(obj, obj.GetValue(VMStackObjectVariable.Category));

            if (obj is VMAvatar)
            {
                VM.AddToObjList(Avatars, obj);
                if (obj.PersistID != 0)
                {
                    AvatarsByPersist[obj.PersistID] = (VMAvatar)obj;
                }
            }

            if (obj.TreeTable != null && obj.TreeTable.AutoInteractions.Length > 0)
            {
                VM.AddToObjList(WithAutonomy, obj);
            }
        }
Ejemplo n.º 3
0
        public override object GetValue(object component)
        {
            if (UseLastValue > 0)
            {
                UseLastValue--;
                return(LastValue);
            }
            switch (Type)
            {
            case VMExtDataType.StackObject:
                return((Frame.StackObject == null)?0:(int)Frame.StackObject.ObjectID);

            case VMExtDataType.Parameter:
                if (ID >= Frame.Args.Length)
                {
                    return(0);
                }
                return((int)Frame.Args[ID]);

            case VMExtDataType.Local:
                if (ID >= Frame.Locals.Length)
                {
                    return(0);
                }
                return((int)Frame.Locals[ID]);

            case VMExtDataType.Attributes:
                return((int)Object.GetAttribute((ushort)ID));

            case VMExtDataType.Temp:
                return((int)Object.Thread.TempRegisters[ID]);

            case VMExtDataType.TempXL:
                return(Object.Thread.TempXL[ID]);

            case VMExtDataType.ObjectData:
                return((int)Object.GetValue((VMStackObjectVariable)ID));

            case VMExtDataType.PersonData:
                try
                {
                    return((int)((VMAvatar)Object).GetPersonData((VMPersonDataVariable)ID));
                } catch (IndexOutOfRangeException) { return(0); }

            case VMExtDataType.Motives:
                return((int)((VMAvatar)Object).GetMotiveData((VMMotive)ID));

            case VMExtDataType.Globals:
                //maybe make this less unbelievably ugly
                return((int)Object.Thread.Context.VM.GetGlobalValue((ushort)ID));
            }
            return(0);
        }
Ejemplo n.º 4
0
        public void RegisterNewObject(VM vm, VMEntity obj, VMAsyncPersistIDCallback callback)
        {
            if (obj is VMAvatar)
            {
                return;                  //???
            }
            var  objid = obj.ObjectID;
            uint guid  = obj.Object.OBJ.GUID;

            if (obj.MasterDefinition != null)
            {
                guid = obj.MasterDefinition.GUID;
            }
            var  state = ((VMTSOObjectState)obj.TSOState);
            uint?owner = state.OwnerID;

            if (owner == 0)
            {
                owner = null;
            }
            DbObject dbo = new DbObject()
            {
                owner_id      = owner,
                lot_id        = Context.DbId,
                shard_id      = Context.ShardId,
                dyn_obj_name  = "",
                budget        = 0,
                graphic       = (ushort)obj.GetValue(VMStackObjectVariable.Graphic),
                type          = guid,
                value         = (uint)obj.MultitileGroup.Price,
                upgrade_level = state.UpgradeLevel
            };

            Host.InBackground(() =>
            {
                try
                {
                    using (var db = DAFactory.Get())
                    {
                        var id = db.Objects.Create(dbo);
                        if (callback != null)
                        {
                            callback(objid, id);
                        }
                    }
                }
                catch (Exception) { callback(objid, 0); }
            });
        }
Ejemplo n.º 5
0
        public void RemoveObject(VMEntity obj)
        {
            var             guid = obj.Object.OBJ.GUID;
            List <VMEntity> list = null;

            ObjectsByGUID.TryGetValue(guid, out list);
            if (list != null)
            {
                VM.DeleteFromObjList(list, obj);
                if (list.Count == 0)
                {
                    ObjectsByGUID.Remove(guid);
                }
            }
            RemoveCategory(obj, obj.GetValue(VMStackObjectVariable.Category));
            if (obj.SemiGlobal != null)
            {
                if (obj.SemiGlobal.Iff.Filename != null) //sanity check
                {
                    RemoveSemiGlobal(obj, obj.SemiGlobal.Iff.Filename.ToLowerInvariant());
                }
            }


            if (obj is VMAvatar)
            {
                Avatars.Remove(obj);
                AvatarsByPersist.Remove(obj.PersistID);
            }
            else if (obj.PersistID > 0 && obj.MultitileGroup.Objects.Count == 1)
            {
                MultitileByPersist.Remove(obj.PersistID);
                if (obj.Thread != null)
                {
                    var vm = obj.Thread.Context.VM;
                    if (vm.PlatformState.LimitExceeded)
                    {
                        VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                    }
                }
            }

            if (obj.TreeTable != null && obj.TreeTable.AutoInteractions.Length > 0)
            {
                WithAutonomy.Remove(obj);
            }
        }
Ejemplo n.º 6
0
        public void NewObject(VMEntity obj)
        {
            var guid = obj.Object.OBJ.GUID;

            ObjectsByGUID.TryGetValue(guid, out var list);
            if (list == null)
            {
                list = new List <VMEntity>();
                ObjectsByGUID.Add(guid, list);
            }
            VM.AddToObjList(list, obj);
            RegisterCategory(obj, obj.GetValue(VMStackObjectVariable.Category));

            if (obj is VMAvatar)
            {
                VM.AddToObjList(Avatars, obj);
                if (obj.PersistID != 0)
                {
                    AvatarsByPersist[obj.PersistID] = (VMAvatar)obj;
                }
            }
        }
Ejemplo n.º 7
0
        public override bool Execute(VM vm, VMAvatar caller)
        {
            if (ObjectPID == 0) //only has value when this is an inventory move.
            {
                VMEntity obj = vm.GetObjectById(ObjectID);
                if (obj == null || caller == null)
                {
                    return(false);
                }
                obj.Delete(CleanupAll, vm.Context);

                // If we're the server, tell the global link to give their money back.
                if (vm.GlobalLink != null)
                {
                    vm.GlobalLink.PerformTransaction(vm, false, uint.MaxValue, caller.PersistID, obj.MultitileGroup.Price,
                                                     (bool success, int transferAmount, uint uid1, uint budget1, uint uid2, uint budget2) =>
                    {
                        vm.SendCommand(new VMNetAsyncResponseCmd(0, new VMTransferFundsState
                        { //update budgets on clients. id of 0 means there is no target thread.
                            Responded      = true,
                            Success        = success,
                            TransferAmount = transferAmount,
                            UID1           = uid1,
                            Budget1        = budget1,
                            UID2           = uid2,
                            Budget2        = budget2
                        }));
                    });
                }
                vm.SignalChatEvent(new VMChatEvent(caller.PersistID, VMChatEventType.Arch,
                                                   caller.Name,
                                                   vm.GetUserIP(caller.PersistID),
                                                   "deleted " + obj.ToString()
                                                   ));
            }
            else
            {
                //inventory move. Just delete the object.
                VMEntity obj = vm.GetObjectByPersist(ObjectPID);
                if (obj == null)
                {
                    return(false);
                }

                if (Success)
                {
                    if (((VMTSOObjectState)obj.TSOState).OwnerID == vm.MyUID)
                    {
                        //if the owner is here, tell them this object is now in their inventory.
                        //if they're elsewhere, they'll see it the next time their inventory updates.
                        //Inventory accesses are not by index, but PID, and straight to DB... so this won't cause any race conditions.
                        vm.MyInventory.Add(new VMInventoryItem()
                        {
                            ObjectPID = ObjectPID,
                            GUID      = (obj.MasterDefinition?.GUID) ?? obj.Object.OBJ.GUID,
                            Name      = obj.MultitileGroup.Name,
                            Value     = (uint)obj.MultitileGroup.Price,
                            Graphic   = (ushort)obj.GetValue(VMStackObjectVariable.Graphic),
                            DynFlags1 = obj.DynamicSpriteFlags,
                            DynFlags2 = obj.DynamicSpriteFlags2,
                        });
                    }
                    vm.Context.ObjectQueries.RemoveMultitilePersist(vm, obj.PersistID);
                    foreach (var o in obj.MultitileGroup.Objects)
                    {
                        o.PersistID = 0;                                           //no longer representative of the object in db.
                    }
                    obj.Delete(CleanupAll, vm.Context);

                    vm.SignalChatEvent(new VMChatEvent(caller.PersistID, VMChatEventType.Arch,
                                                       caller?.Name ?? "disconnected user",
                                                       vm.GetUserIP(caller.PersistID),
                                                       "sent " + obj.ToString() + " back to the inventory of its owner."
                                                       ));
                }
                else
                {
                    //something bad happened. just unlock the object.
                    foreach (var o in obj.MultitileGroup.Objects)
                    {
                        ((VMGameObject)o).Disabled &= VMGameObjectDisableFlags.TransactionIncomplete;
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
 public string EntityInfo(VMEntity ent)
 {
     return($"{ent.ToString()} at {ent.Position.ToString()}. Contained in { ent.Container?.ToString() ?? "null" }, " +
            $"Dead: { ent.Dead.ToString() }, Flags: { ent.GetValue(Model.VMStackObjectVariable.Flags).ToString("X4") }.");
 }