public void OnCorpseDisturb(NWPlaceable corpse) { NWPlayer oPC = NWPlayer.Wrap(_.GetLastDisturbed()); if (!oPC.IsPlayer && !oPC.IsDM) { return; } NWItem oItem = NWItem.Wrap(_.GetInventoryDisturbItem()); int disturbType = _.GetInventoryDisturbType(); if (disturbType == INVENTORY_DISTURB_TYPE_ADDED) { _.ActionGiveItem(oItem.Object, oPC.Object); oPC.FloatingText("You cannot put items into corpses."); } else { PCCorpseItem dbItem = _db.PCCorpseItems.SingleOrDefault(x => x.GlobalID == oItem.GlobalID); if (dbItem == null) { return; } _db.PCCorpseItems.Remove(dbItem); _db.SaveChanges(); } }
public void OnPlayerDeath() { NWPlayer oPC = NWPlayer.Wrap(_.GetLastPlayerDied()); string corpseName = oPC.Name + "'s Corpse"; NWObject oHostileActor = NWObject.Wrap(_.GetLastHostileActor(oPC.Object)); Location location = oPC.Location; bool hasItems = false; var factionMember = _.GetFirstFactionMember(oHostileActor.Object, FALSE); while (_.GetIsObjectValid(factionMember) == TRUE) { _.ClearPersonalReputation(oPC.Object, factionMember); factionMember = _.GetNextFactionMember(oHostileActor.Object, FALSE); } _.PopUpDeathGUIPanel(oPC.Object, TRUE, TRUE, 0, RespawnMessage); NWPlaceable corpse = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, CorpsePlaceableResref, location)); PCCorpse entity = new PCCorpse { AreaTag = _.GetTag(_.GetAreaFromLocation(location)), Name = corpseName, Orientation = _.GetFacingFromLocation(location), PositionX = _.GetPositionFromLocation(location).m_X, PositionY = _.GetPositionFromLocation(location).m_Y, PositionZ = _.GetPositionFromLocation(location).m_Z }; if (oPC.Gold > 0) { corpse.AssignCommand(() => { _.TakeGoldFromCreature(oPC.Gold, oPC.Object); }); hasItems = true; } foreach (NWItem item in oPC.InventoryItems) { if (!item.IsCursed) { _.CopyItem(item.Object, corpse.Object, TRUE); item.Destroy(); hasItems = true; } } if (!hasItems) { corpse.Destroy(); return; } corpse.Name = corpseName; corpse.IdentifiedDescription = corpseName; foreach (NWItem corpseItem in corpse.InventoryItems) { PCCorpseItem corpseItemEntity = new PCCorpseItem { GlobalID = corpseItem.GlobalID, NWItemObject = _serialization.Serialize(corpseItem), PCCorpseItemID = entity.PCCorpseID, ItemName = corpseItem.Name, ItemTag = corpseItem.Tag, ItemResref = corpseItem.Resref }; entity.PCCorpseItems.Add(corpseItemEntity); } _db.PCCorpses.Add(entity); _db.SaveChanges(); corpse.SetLocalInt("CORPSE_ID", (int)entity.PCCorpseID); }