/// <summary> /// Called right before spawning. Responsible for creating loot holders for any lootables /// </summary> protected override void OnAwake() { switch (goType) { case GameObjectType.Plant: case GameObjectType.Vein: { this.lootContainer = new FixedLootContainer(this, lootGroupId, (itemId, looter) => true, null, player => { this.HideFromPlayer(player.Guid); this.World.PrimaryFiber.Schedule(() => this.UnhideFromPlayer(player.Guid), ServerGameSettings.GATHER_RESPAWN_TIME_MS); }); this.lootGeneration = 0; } break; case GameObjectType.Chest: { this.lootContainer = new RandomLootContainer(this, lootGroupId, (itemId, looter) => true); this.lootGeneration = 0; } break; } }
/// <summary> /// Called when this <see cref="Character"/> is killed. Remember the <paramref name="killer"/> could be <value>this</value>. /// </summary> protected override void OnDeath(MmoObject killer) { base.OnDeath(killer); if (IsMoving) { this.ResetMovement(); this.PublishStopEvent(); } this.DisposeRadarSubscriptions(); this.CurrentAggroState = AggroState.Idle; this.CurrentFocus = null; RandomLootContainer randomLootContainer = null; ICollection <MmoGuid> skipPlayers = null; foreach (var pair in threatTable) { // only players can be rewarded for now var pGuid = pair.Key; if (pGuid.Type != (byte)ObjectType.Player) { continue; } // reward only if the threat is greater than this threshold if (pair.Value <= ServerGameSettings.THREAT_THRESHOLD_FOR_REWARD) { continue; } if (skipPlayers != null) { // making sure the player gets only one loot generation attempt if (skipPlayers.Contains(pGuid)) { continue; } skipPlayers.Add(pGuid); } WorldSession session; if (MmoWorld.Instance.SessionCache.TryGetSessionByPlayerGuid(pGuid.Id, out session)) { // generate loot, only if one of the killer is a player if (randomLootContainer == null) { randomLootContainer = new RandomLootContainer(this, this.lootGroupId, (itemId, looter) => true); } // create the collection only if one killer is a player if (skipPlayers == null) { skipPlayers = this.threatTable.Count > 10 ? (ICollection <MmoGuid>) new HashSet <MmoGuid>() : new List <MmoGuid>(); } var player = session.Player; // player is in a group if (player.InGroup()) { var members = player.Group.GetActiveMembers(); foreach (var member in members) { // making sure the member gets only one loot generation attempt var mGuid = member.Guid; if (skipPlayers.Contains(mGuid)) { continue; } skipPlayers.Add(mGuid); // finding the player WorldSession memberSession; if (MmoWorld.Instance.SessionCache.TryGetSessionByPlayerGuid(mGuid.Id, out memberSession)) { continue; } // checking to see if the player is within the range of the member var memberPlayer = memberSession.Player; if (!player.HaveSubscriptionFor(memberPlayer.Guid) && player != memberPlayer) { continue; } randomLootContainer.GenerateLootFor(memberPlayer); } } // always generate loot for the player randomLootContainer.GenerateLootFor(player); player.RewardKill(this); } } this.threatTable.Clear(); var spawnDelay = ServerGameSettings.BASE_NPC_RESPAWN_TIME_MS; if (randomLootContainer != null) { spawnDelay = ServerGameSettings.BASE_NPC_WAIT_TIME_UNTIL_LOOTED_MS; // set the loot lootContainer = randomLootContainer; // notify all the looters randomLootContainer.NotifyLooters(); } this.QueueRespawn(spawnDelay, ServerGameSettings.BASE_NPC_RESPAWN_TIME_MS, this.iPosition, this.iRotation); }