private void AddChest(Vector3 location, bool locked, bool trapped, bool addHealth) { int id = Game.EntityManager.CreateEntity(); var formComp = new FormComponent(); formComp.InitComponent(id, location, "Chest001", "Chest001_Broken"); Game.EntityManager.AddComponent(id, formComp); var openComp = new OpenComponent(); openComp.InitComponent(null); Game.EntityManager.AddComponent(id, openComp); var animComp = new AnimationComponent(); animComp.InitComponent(null); animComp.Animations.Add(new AnimationSystem.AnimationData() { EntityID = id, Name = "ChestClose", Sound = "ChestClose001", DisablePhysics = true, TriggerEvent = RPGGameEvent.Menu_Close }); animComp.Animations.Add(new AnimationSystem.AnimationData() { EntityID = id, Name = "ChestOpen90", Sound = "ChestOpen001", DisablePhysics = true, TriggerEvent = RPGGameEvent.Menu_Open }); Game.EntityManager.AddComponent(id, animComp); if (locked) { var lockComp = new LockComponent(); lockComp.InitComponent(null); lockComp.InitComponent(44); Game.EntityManager.AddComponent(id, lockComp); } if (trapped) { var trapComp = new TrapComponent(); trapComp.InitComponent(formComp, new EffectSystem.EffectData() { AreaOfEffectRadius = 10, Duration = 5, PrefabName = "AOE/Fireball", TargetType = EffectSystem.TargetTypeEnum.AreaOfEffect, Damage = new DieRollData(2, 4, 0, 0), DamageType = AttackSystem.DamageTypes.Crush, Description_Attack = "Fireball Blast" }); Game.EntityManager.AddComponent(id, trapComp); } if (addHealth) { var health = new HealthComponent() { Damage = 0, DeathType = HealthComponent.DeathTypes.Broken, HP_Max = 5000 }; Game.EntityManager.AddComponent(id, health); } }
private void OnExamined(EntityUid uid, LockComponent lockComp, ExaminedEvent args) { args.PushText(Loc.GetString(lockComp.Locked ? "lock-comp-on-examined-is-locked" : "lock-comp-on-examined-is-unlocked", ("entityName", EntityManager.GetComponent <MetaDataComponent>(lockComp.Owner).EntityName))); }
public static async ETTask Lock(this LockComponent self) { ++self.lockCount; if (self.status == LockStatus.Locked) { return; } if (self.status == LockStatus.LockRequesting) { await self.WaitLock(); return; } self.status = LockStatus.LockRequesting; // 真身直接本地请求锁,镜像需要调用Rpc获取锁 MasterComponent masterComponent = self.Entity.GetComponent <MasterComponent>(); if (masterComponent != null) { await masterComponent.Lock(self.address); } else { self.RequestLock().NoAwait(); await self.WaitLock(); } }
/// <summary> /// 加锁 只有成功后,才会有 返回值 /// </summary> /// <param name="self"></param> /// <returns></returns> public static async Task Lock(this LockComponent self) { ++self.lockCount; //加锁次数++ if (self.status == LockStatus.Locked) //如果已经锁定 跳出 { return; } if (self.status == LockStatus.LockRequesting) //如过当前是待加锁状态 { await self.WaitLock(); return; } self.status = LockStatus.LockRequesting; //待加锁状态 // 真身直接本地请求锁,镜像需要调用Rpc获取锁 MasterComponent masterComponent = self.Entity.GetComponent <MasterComponent>(); if (masterComponent != null) { await masterComponent.Lock(self.address); } else { self.RequestLock(); await self.WaitLock(); } }
private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args) { if (EntityManager.TryGetComponent(lockComp.Owner, out AppearanceComponent? appearance)) { appearance.SetData(StorageVisuals.CanLock, true); } }
/// <summary> /// 请求加锁 /// </summary> /// <param name="self"></param> private static async void RequestLock(this LockComponent self) { try { ///这个需要加锁的角色的IP Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.address); string serverAddress = StartConfigComponent.Instance.StartConfig.ServerIP; G2G_LockRequest request = new G2G_LockRequest { Id = self.Entity.Id, Address = serverAddress }; await session.Call(request); self.status = LockStatus.Locked; //所有的请求都确定 加锁成功 foreach (TaskCompletionSource <bool> taskCompletionSource in self.queue) { taskCompletionSource.SetResult(true); } self.queue.Clear(); } catch (Exception e) { Log.Error($"获取锁失败: {self.address} {self.Entity.Id} {e}"); } }
private void OnExamined(EntityUid eUI, LockComponent lockComp, ExaminedEvent args) { args.Message.AddText("\n"); args.Message.AddText(Loc.GetString(lockComp.Locked ? "lock-comp-on-examined-is-locked" : "lock-comp-on-examined-is-unlocked", ("entityName", lockComp.Owner.Name))); }
private void OnStorageOpenAttempt(EntityUid uid, LockComponent component, StorageOpenAttemptEvent args) { if (component.Locked) { if (!args.Silent) { _sharedPopupSystem.PopupEntity(Loc.GetString("entity-storage-component-locked-message"), uid, Filter.Pvs(uid)); } args.Cancel(); } }
private static ETTask <bool> WaitLock(this LockComponent self) { if (self.status == LockStatus.Locked) { return(ETTask.FromResult(true)); } ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); self.queue.Enqueue(tcs); return(tcs.Task); }
/// <summary> /// 等待加锁 /// </summary> /// <param name="self"></param> /// <returns></returns> private static Task <bool> WaitLock(this LockComponent self) { if (self.status == LockStatus.Locked) { return(Task.FromResult(true)); } TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); self.queue.Enqueue(tcs); //加入到待加锁的字典中 return(tcs.Task); //等待返回 }
private static bool HasUserAccess(LockComponent lockComp, IEntity user) { if (lockComp.Owner.TryGetComponent(out AccessReader? reader)) { if (!reader.IsAllowed(user)) { lockComp.Owner.PopupMessage(user, Loc.GetString("lock-comp-has-user-access-fail")); return(false); } } return(true); }
private static bool PickLockResult(SkillComponent skillComp, LockComponent lockComp) { if (!lockComp.IsPickable) { return(false); } bool success = skillComp.PickLockLevel >= lockComp.PickSkillLevel; // could make more complicated return(success); }
/// <summary> /// 解锁 /// </summary> /// <param name="self"></param> /// <returns></returns> public static async Task Release(this LockComponent self) { --self.lockCount; if (self.lockCount != 0) { return; } self.status = LockStatus.LockedNot; //设置为不加锁状态 Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.address); //获取他的地址 G2G_LockReleaseRequest request = new G2G_LockReleaseRequest(); await session.Call(request); //发送解锁消息 }
private void OnActivated(EntityUid eUI, LockComponent lockComp, ActivateInWorldEvent args) { // Only attempt an unlock by default on Activate if (lockComp.Locked) { DoUnlock(lockComp, args); } else { if (lockComp.LockOnClick) { DoLock(lockComp, args); } } }
private void AddToggleLockVerb(EntityUid uid, LockComponent component, GetVerbsEvent <AlternativeVerb> args) { if (!args.CanAccess || !args.CanInteract || !CanToggleLock(uid, args.User)) { return; } AlternativeVerb verb = new(); verb.Act = component.Locked ? () => TryUnlock(uid, args.User, component) : () => TryLock(uid, args.User, component); verb.Text = Loc.GetString(component.Locked ? "toggle-lock-verb-unlock" : "toggle-lock-verb-lock"); // TODO VERB ICONS need padlock open/close icons. args.Verbs.Add(verb); }
private void OnEmagged(EntityUid uid, LockComponent component, GotEmaggedEvent args) { if (component.Locked == true) { if (component.UnlockSound != null) { SoundSystem.Play(Filter.Pvs(component.Owner), component.UnlockSound.GetSound(), component.Owner, AudioParams.Default.WithVolume(-5)); } if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComp)) { appearanceComp.SetData(StorageVisuals.Locked, false); } EntityManager.RemoveComponent <LockComponent>(uid); //Literally destroys the lock as a tell it was emagged args.Handled = true; } }
private void OnActivated(EntityUid uid, LockComponent lockComp, ActivateInWorldEvent args) { if (args.Handled) { return; } // Only attempt an unlock by default on Activate if (lockComp.Locked) { TryUnlock(uid, args.User, lockComp); args.Handled = true; } else if (lockComp.LockOnClick) { TryLock(uid, args.User, lockComp); args.Handled = true; } }
public void DoLock(LockComponent lockComp, ActivateInWorldEvent args) { if (!HasUserAccess(lockComp, args.User)) { return; } lockComp.Owner.PopupMessage(args.User, Loc.GetString("lock-comp-do-lock-success", ("entityName", lockComp.Owner.Name))); lockComp.Locked = true; if (lockComp.LockSound != null) { SoundSystem.Play(Filter.Pvs(lockComp.Owner), lockComp.LockSound.GetSound(), lockComp.Owner, AudioParams.Default.WithVolume(-5)); } if (lockComp.Owner.TryGetComponent(out AppearanceComponent? appearanceComp)) { appearanceComp.SetData(StorageVisuals.Locked, true); } RaiseLocalEvent(lockComp.Owner.Uid, new LockToggledEvent(true)); args.Handled = true; }
public static void Awake(this LockComponent self, IPEndPoint addr) { self.address = addr; }