public ItemPickupEvent(CollectibleEntity collectibleEntity, BaseEntity.RPCMessage msg, Item item) { Entity = collectibleEntity; RPCMessage = msg; Player = Server.GetPlayer(msg.player); Item = new InvItem(item); }
public ItemRepairEvent(RepairBench repairBench, BaseEntity.RPCMessage msg) { RepairBench = repairBench; RPCMessage = msg; Player = Server.GetPlayer(msg.player); Item = new InvItem(repairBench.inventory.GetSlot(0)); }
public GatherEvent(ResourceDispenser resourceDispenser, BaseEntity from, BaseEntity to, ItemAmount itemAmount, int amount) { if (to is BasePlayer) { ResourceDispenser = resourceDispenser; Resource = new Entity(from); Gatherer = Server.GetPlayer(to as BasePlayer); ItemAmount = itemAmount; Amount = (int)(amount * World.GetInstance().ResourceGatherMultiplier); } }
public virtual bool Equals(BaseEntity other) { if (other == null) return false; if (ReferenceEquals(this, other)) return true; if (!IsTransient(this) && !IsTransient(other) && Equals(Id, other.Id)) { var otherType = other.GetUnproxiedType(); var thisType = GetUnproxiedType(); return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType); } return false; }
/// <summary> /// Called from <c>RepairBench.RepairItem(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_ItemRepaired(RepairBench rb, BaseEntity.RPCMessage msg) => OnNext("On_ItemRepaired", new ItemRepairEvent(rb, msg));
/// <summary> /// Called from <c>BaseProjectile.CLProject(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerShoot(BaseProjectile baseProjectile, BaseEntity.RPCMessage msg) { OnNext("On_PlayerShoot", new ShootEvent(baseProjectile, msg)); }
/// <summary> /// Called from <c>BaseLauncher.SV_Launch(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerShootRocket(BaseLauncher baseLauncher, BaseEntity.RPCMessage msg, BaseEntity baseEntity) { OnNext("On_PlayerShootRocket", new ShootRocketEvent(baseLauncher, msg, baseEntity)); }
/// <summary> /// Called from <c>Door.RPC_OpenDoor(BaseEntity.RPCMessage)</c> and <c>Door.RPC_CloseDoor(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_DoorUse(Door door, BaseEntity.RPCMessage msg, bool open) { if ((open && door.IsOpen()) || (!open && !door.IsOpen())) return; var preDoorUseEvent = new Pre<DoorUseEvent>(door, msg, open); OnNext("Pre_DoorUse", preDoorUseEvent); if (preDoorUseEvent.IsCanceled) { if (preDoorUseEvent.Event.DenyReason != "") msg.player.SendConsoleCommand("chat.add", 0, String.Format("{0}: {1}", Server.server_message_name.ColorText("fa5"), preDoorUseEvent.Event.DenyReason)); return; } bool doAction = true; BaseLock baseLock = door.GetSlot(BaseEntity.Slot.Lock) as BaseLock; if (baseLock != null && preDoorUseEvent.Event.IgnoreLock == false) { doAction = open ? baseLock.OnTryToOpen(msg.player) : baseLock.OnTryToClose(msg.player); if (doAction && open && (baseLock.IsLocked() && Time.realtimeSinceStartup - (float)door.GetFieldValue("decayResetTimeLast") > 60)) { Decay.RadialDecayTouch(door.transform.position, 40, 270532608); door.SetFieldValue("decayResetTimeLast", Time.realtimeSinceStartup); } } if (doAction) { door.SetFlag(BaseEntity.Flags.Open, open); door.SendNetworkUpdateImmediate(false); door.CallMethod("UpdateDoorAnimationParameters", false); OnNext("On_DoorUse", preDoorUseEvent.Event); } }
/// <summary> /// Called from <c>ResourceDispenser.GiveResourceFromItem(BaseEntity, ItemAmount, float, float, AttackEntity)</c> . /// </summary> public static void On_PlayerGathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmount, float gatherDamage, float destroyFraction) { BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity"); if (itemAmount.amount == 0) return; float num = gatherDamage / from.MaxHealth(); float num2 = itemAmount.startAmount / (float)dispenser.GetFieldValue("startingItemCounts"); float value = itemAmount.startAmount * num / num2; float num3 = Mathf.Clamp(value, 0, itemAmount.amount); float num4 = num3 * destroyFraction * 2; if (itemAmount.amount < num3 + num4) { itemAmount.amount -= destroyFraction * num3; num3 = itemAmount.amount; num4 = 0; } float amount = itemAmount.amount; itemAmount.amount -= num3; if (itemAmount.amount < 0) { itemAmount.amount = 0; } int num5 = Mathf.Clamp(Mathf.RoundToInt(num3), 0, Mathf.CeilToInt(amount)); itemAmount.amount -= num4; if (itemAmount.amount < 0) { itemAmount.amount = 0; } GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmount, num5); OnNext("On_PlayerGathering", ge); if (ge.Amount <= 0) return; Item item = ItemManager.CreateByItemID(itemAmount.itemid, ge.Amount); if (item == null) return; to.GiveItem(item, BaseEntity.GiveItemReason.ResourceHarvested); }
public ThrowEvent(ThrownWeapon thrownWeapon, BaseEntity.RPCMessage msg) { Projectile = thrownWeapon; Player = Server.GetPlayer(msg.player); ProjectileName = ExplosiveNames[thrownWeapon.ShortPrefabName]; }
public Entity(BaseEntity ent) { baseEntity = ent; Prefab = baseEntity.PrefabName; PrefabID = baseEntity.prefabID; }
private static bool IsTransient(BaseEntity obj) { return obj != null && Equals(obj.Id, default(int)); }
public DoorUseEvent(Door door, BaseEntity.RPCMessage msg, bool open) { Door = new Entity(door); Player = Server.GetPlayer(msg.player); Open = open; }
/// <summary> /// Called from <c>CollectibleEntity.Pickup(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_ItemPickup(CollectibleEntity entity, BaseEntity.RPCMessage msg) { if (!msg.player.IsAlive() || !msg.player.CanInteract() || entity.itemList == null) return; foreach (ItemAmount itemAmount in entity.itemList) { Item item = ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, 0); OnNext("On_ItemPickup", new ItemPickupEvent(entity, msg, item)); msg.player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp); } entity.itemList = null; if (entity.pickupEffect.isValid) { Effect.server.Run(entity.pickupEffect.resourcePath, entity.transform.position, entity.transform.up, null, false); } entity.Kill(BaseNetworkable.DestroyMode.None); }
/// <summary> /// Called from <c>ThrownWeapon.DoThrow(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerThrowExplosive(ThrownWeapon thrownWeapon, BaseEntity.RPCMessage msg) { ThrowEvent evt = new ThrowEvent(thrownWeapon, msg); switch (evt.ProjectileName) { case "F1 Grenade": case "Beancan Grenade": OnNext("On_PlayerThrowGrenade", evt); break; case "Timed Explosive Charge": case "Survey Charge": case "Satchel Charge": OnNext("On_PlayerThrowCharge", evt); break; case "Supply Signal": OnNext("On_PlayerThrowSignal", evt); break; } }
/// <summary> /// Called from <c>BaseMelee.CLProject(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerThrowWeapon(BaseMelee baseMelee, BaseEntity.RPCMessage msg) { BasePlayer messagePlayer = msg.player; if ((bool) baseMelee.CallMethod("VerifyClientAttack", messagePlayer) == false) { baseMelee.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (!baseMelee.canThrowAsProjectile){ Debug.LogWarning(messagePlayer + " fired invalid projectile: Not throwable"); return; } Item item = baseMelee.GetItem(); if (item == null) { Debug.LogWarning(messagePlayer + " fired invalid projectile: Item not found"); return; } ItemModProjectile component = item.info.GetComponent<ItemModProjectile>(); if (component == null) { Debug.LogWarning(messagePlayer + " fired invalid projectile: Item mod not found"); return; } ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read); if (projectileShoot.projectiles.Count != 1){ Debug.LogWarning(messagePlayer + " fired invalid projectile: Projectile count mismatch"); return; } messagePlayer.CleanupExpiredProjectiles(); foreach (ProjectileShoot.Projectile current in projectileShoot.projectiles) { if (messagePlayer.HasFiredProjectile(current.projectileID)) { Debug.LogWarning(messagePlayer + " fired invalid projectile: Duplicate ID ->" + current.projectileID); } else { Pre<WeaponThrowEvent> preWeaponThrowEvent = new Pre<WeaponThrowEvent>(baseMelee, messagePlayer, projectileShoot, current); OnNext("Pre_PlayerThrowWeapon", preWeaponThrowEvent); if (preWeaponThrowEvent.IsCanceled == false) { messagePlayer.NoteFiredProjectile(current.projectileID, current.startPos, current.startVel, baseMelee, item.info, item); Effect effect = new Effect(); effect.Init(Effect.Type.Projectile, current.startPos, current.startVel.normalized, msg.connection); effect.scale = preWeaponThrowEvent.Event.Magnitude; effect.pooledString = component.projectileObject.resourcePath; effect.number = current.seed; EffectNetwork.Send(effect); OnNext("On_PlayerThrowWeapon", preWeaponThrowEvent.Event); } } } item.SetParent(null); }
/// <summary> /// Called from <c>MedicalTool.UseOther(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerSyringeOther(MedicalTool medicalTool, BaseEntity.RPCMessage msg) { BasePlayer messagePlayer = msg.player; if (messagePlayer.CanInteract() == false) return; if ((bool)medicalTool.CallMethod("HasItemAmount") == false || medicalTool.canUseOnOther == false) return; BasePlayer owner = medicalTool.GetOwnerPlayer(); if (owner == null) return; BasePlayer target = BaseNetworkable.serverEntities.Find(msg.read.UInt32()) as BasePlayer; if (target != null && Vector3.Distance(target.transform.position, owner.transform.position) < 4f) { var preSyringeUseEvent = new Pre<SyringeUseEvent>(medicalTool, owner, target); OnNext("Pre_PlayerSyringeOther", preSyringeUseEvent); if (preSyringeUseEvent.IsCanceled == false) { medicalTool.ClientRPCPlayer(null, messagePlayer, "Reset"); medicalTool.CallMethod("GiveEffectsTo", target); medicalTool.CallMethod("UseItemAmount", 1); OnNext("On_PlayerSyringeOther", preSyringeUseEvent.Event); } } }
/// <summary> /// Called from <c>MedicalTool.UseSelf(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_PlayerSyringeSelf(MedicalTool medicalTool, BaseEntity.RPCMessage msg) { BasePlayer messagePlayer = msg.player; if (messagePlayer.CanInteract() == false) return; if ((bool)medicalTool.CallMethod("HasItemAmount") == false) return; BasePlayer owner = medicalTool.GetOwnerPlayer(); var preSyringeUseEvent = new Pre<SyringeUseEvent>(medicalTool, owner, owner); OnNext("Pre_PlayerSyringeSelf", preSyringeUseEvent); if (preSyringeUseEvent.IsCanceled == false) { medicalTool.ClientRPCPlayer(null, messagePlayer, "Reset"); medicalTool.CallMethod("GiveEffectsTo", owner); medicalTool.CallMethod("UseItemAmount", 1); OnNext("On_PlayerSyringeSelf", preSyringeUseEvent.Event); } }
public CorpseInitEvent(BaseCorpse baseCorpse, BaseEntity baseEntity) { Corpse = baseCorpse; Parent = new Entity(baseEntity); }
/// <summary> /// Called from <c>BuildingBlock.DoUpgradeToGrade(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_BuildingUpgrade(BuildingBlock block, BaseEntity.RPCMessage msg) { BasePlayer messagePlayer = msg.player; BuildingGrade.Enum buildingGrade = (BuildingGrade.Enum) msg.read.Int32(); ConstructionGrade constructionGrade = (ConstructionGrade) block.CallMethod("GetGrade", buildingGrade); Pre<BuildingUpgradeEvent> preBuildingUpgradeEvent = new Pre<BuildingUpgradeEvent>(block, buildingGrade, messagePlayer); OnNext("Pre_BuildingUpgrade", preBuildingUpgradeEvent); if (preBuildingUpgradeEvent.IsCanceled) return; if (constructionGrade == null) return; if ((bool) block.CallMethod("CanChangeToGrade", buildingGrade, messagePlayer) == false) return; if ((bool)block.CallMethod("CanAffordUpgrade", buildingGrade, messagePlayer) == false) return; block.CallMethod("PayForUpgrade", constructionGrade, messagePlayer); block.SetGrade(buildingGrade); block.SetHealthToMax(); block.CallMethod("StartBeingRotatable"); block.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); block.UpdateSkin(false); Effect.server.Run("assets/bundled/prefabs/fx/build/promote_" + buildingGrade.ToString().ToLower() + ".prefab", block, 0u, Vector3.zero, Vector3.zero); OnNext("On_BuildingUpgrade", preBuildingUpgradeEvent.Event); }
public ShootRocketEvent(BaseLauncher baseLauncher, BaseEntity.RPCMessage msg, BaseEntity baseEntity) { BaseLauncher = baseLauncher; Entity = new Entity(baseEntity); Player = Server.GetPlayer(msg.player); }
/// <summary> /// Called from <c>BuildingBlock.DoDemolish(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_BuildingPartDemolished(BuildingBlock bb, BaseEntity.RPCMessage msg) => OnNext("On_BuildingPartDemolished", new BuildingPartDemolishedEvent(bb, msg.player));
public ShootEvent(BaseProjectile baseProjectile, BaseEntity.RPCMessage msg) { BaseProjectile = baseProjectile; Player = Server.GetPlayer(msg.player); }
/// <summary> /// Called from <c>CodeLock.UnlockWithCode(BaseEntity.RPCMessage)</c> /// </summary> public static void On_DoorCodeEntered(CodeLock codeLock, BaseEntity.RPCMessage rpc) { if (!codeLock.IsLocked()) return; string code = rpc.read.String(); Pre<DoorCodeEvent> preDoorCodeEvent = new Pre<DoorCodeEvent>(codeLock, rpc.player, code); OnNext("Pre_DoorCodeEntered", preDoorCodeEvent); if (preDoorCodeEvent.IsCanceled || (!preDoorCodeEvent.Event.IsCorrect() && !preDoorCodeEvent.Event.ForceAllow)) { Effect.server.Run(codeLock.effectDenied.resourcePath, codeLock, 0u, Vector3.zero, Vector3.forward); rpc.player.Hurt(1f, global::Rust.DamageType.ElectricShock, codeLock, true); return; } Effect.server.Run(codeLock.effectUnlocked.resourcePath, codeLock, 0u, Vector3.zero, Vector3.forward); codeLock.SetFlag(BaseEntity.Flags.Locked, false); codeLock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); List<ulong> whitelist = new List<ulong>(); whitelist = (List<ulong>) codeLock.GetFieldValue("whitelistPlayers"); if (!whitelist.Contains(rpc.player.userID)) { whitelist.Add(rpc.player.userID); codeLock.SetFieldValue("whitelistPlayers", whitelist); } OnNext("On_DoorCodeEntered", preDoorCodeEvent.Event); }