/// <summary> /// Check whether it's actually possible to do the combine. /// </summary> /// <param name="selectedTarget"></param> /// <returns></returns> public override bool CheckBeginCast(GameLiving selectedTarget) { if (!base.CheckBeginCast(selectedTarget)) { return(false); } if (!(Caster is GamePlayer player)) { return(false); } InventoryItem scroll = player.UseItem; if (scroll == null || !ArtifactMgr.IsArtifactScroll(scroll)) { return(false); } var backpack = player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack); foreach (InventoryItem item in backpack) { if (item != null && item != scroll) { if (ArtifactMgr.CanCombine(scroll, item)) { return(true); } } } return(false); }
/// <summary> /// Do the combine. /// </summary> /// <param name="target"></param> /// <param name="effectiveness"></param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { GamePlayer player = Caster as GamePlayer; if (player == null) { return; } InventoryItem useItem = player.UseItem; if (useItem == null || !ArtifactMgr.IsArtifactScroll(useItem)) { return; } WorldInventoryItem combinedScroll = WorldInventoryItem.CreateFromTemplate("artifact_scroll"); if (combinedScroll == null) { return; } combinedScroll.AddOwner(player); combinedScroll.Name = useItem.Name; combinedScroll.Item.Name = useItem.Name; var backpack = player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack); ArrayList removeItems = new ArrayList(); removeItems.Add(useItem); bool combinesToBook = false; foreach (InventoryItem item in backpack) { if (item == null) { continue; } if (ArtifactMgr.CanCombine(combinedScroll.Item, item)) { combinedScroll = ArtifactMgr.CombineScrolls(combinedScroll.Item, item, ref combinesToBook); removeItems.Add(item); if (combinesToBook) { break; } } } player.Out.SendSpellEffectAnimation(player, player, 1, 0, false, 1); Artifact artifact = ArtifactMgr.GetArtifact(combinedScroll.Item); if (artifact == null) { log.Warn(String.Format("Missing artifact for item '{0}'", combinedScroll.Name)); } else { String receiveMessage = (combinesToBook) ? artifact.MessageReceiveBook : artifact.MessageReceiveScrolls; player.Out.SendMessage(String.Format(receiveMessage, combinedScroll.Name, useItem.Name), eChatType.CT_Skill, eChatLoc.CL_SystemWindow); } if (player.ReceiveItem(player, combinedScroll)) { foreach (InventoryItem item in removeItems) { player.Inventory.RemoveItem(item); InventoryLogging.LogInventoryAction(player, "(ARTIFACT;CombineScrolls)", eInventoryActionType.Quest, item.Template, item.Count); } } }