Monsters are stuck on MODE_IDLE and not attacking players
This code will fix the problem of the droped itens not displaying correct durability and other stats.
This code will prevent showing wrong item durability after level upgrade:
Nevermind, i fixed.Quote:
Monsters are stuck on MODE_IDLE and not attacking players
This code will fix the problem of the droped itens not displaying correct durability and other stats.
//Character.cs
public
bool PickMapItem(uint idItem)
{
var pMapItem = Map.QueryRole(idItem) as MapItem;
if (pMapItem == null)
return false;
if (GetDistance(pMapItem) > 0) {
Send(ServerString.STR_TARGET_NOT_IN_RANGE);
return false;
}
if (!pMapItem.IsMoney()
&& Inventory.RemainingSpace() <= 0) {
Send(ServerString.STR_INVENTORY_FULL);
return false;
}
uint idOwner = pMapItem.GetPlayerId();
if (pMapItem.IsPriv() && idOwner != Identity) {
var pOwner = Map.QueryRole(idOwner) as Character;
if (pOwner != null && !IsMate(pOwner)) {
if (Team != null && Team.IsTeamMember(pOwner)) {
if ((pMapItem.IsMoney() && Team.IsCloseMoney) || ((pMapItem.Type == SpecialItem.TYPE_DRAGONBALL || pMapItem.Type == SpecialItem.TYPE_METEOR) && Team.IsCloseGem)
|| (!pMapItem.IsMoney() && pMapItem.Type != SpecialItem.TYPE_DRAGONBALL && pMapItem.Type != SpecialItem.TYPE_METEOR && Team.IsCloseItem)) {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
else {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
else if (pOwner != null && pOwner != this) {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
if (pMapItem.IsMoney()) {
AwardMoney(pMapItem.GetAmount());
if (pMapItem.GetAmount() > 1000)
Send(new MsgAction(Identity, pMapItem.GetAmount(), MapX, MapY, GeneralActionType.GET_MONEY));
Send(string.Format(ServerString.STR_PICK_MONEY, pMapItem.GetAmount()));
}
else {
var pItem = pMapItem.GetInfo(this);
if (pItem != null) {
var newItem = new DbItem{
AddLife = pItem.Enchantment,
AddlevelExp = pItem.CompositionProgress,
AntiMonster = 0,
ArtifactExpire = pItem.ArtifactExpire,
ArtifactType = pItem.ArtifactType,
ChkSum = 0,
Color = 3,
Data = pItem.SocketProgress,
Gem1 = (byte)pItem.SocketOne,
Gem2 = (byte)pItem.SocketTwo,
Ident = 0,
Magic1 = (byte)pItem.Effect,
Magic2 = 0,
ReduceDmg = pItem.ReduceDamage,
Plunder = pItem.LockTime,
Specialflag = 0,
Inscribed = 0,
StackAmount = pItem.StackAmount,
RefineryExpire = pItem.RefineryExpire,
RefineryLevel = pItem.RefineryLevel,
RefineryType = pItem.RefineryType,
Type = pItem.Type,
Position = 0,
PlayerId = 0,
Monopoly = pItem.Monopoly,
Magic3 = pItem.Plus,
Amount = pItem.Durability,
AmountLimit = pItem.MaximumDurability
};
Inventory.Create(newItem);
//Console.WriteLine("////");
//Console.WriteLine(pItem.Durability);
if (pItem.Type == SpecialItem.TYPE_DRAGONBALL
&& Owner.VipLevel >= 2
&& Inventory.ContainsMultiple(SpecialItem.TYPE_DRAGON BALL, SpecialItem.TYPE_DRAGONBALL, 10)) {
Inventory.DeleteMultiple(SpecialItem.TYPE_DRAGONBA LL, SpecialItem.TYPE_DRAGONBALL, 10);
Inventory.Create(SpecialItem.TYPE_DRAGONBALL_SCROL L);
}
if (pItem.Type == SpecialItem.TYPE_METEOR
&& Owner.VipLevel >= 2
&& Inventory.ContainsMultiple(SpecialItem.TYPE_METEOR , SpecialItem.TYPE_METEOR, 10)) {
Inventory.DeleteMultiple(SpecialItem.TYPE_METEOR, SpecialItem.TYPE_METEOR, 10);
Inventory.Create(SpecialItem.TYPE_METEOR_SCROLL);
}
ServerKernel.Log.GmLog("pick_item", string.Format("{0}({1}) pick item:[id={2}, type={3}], dur={4}, max_dur={5}", Name, Identity, pItem.Identity, pItem.Type, pItem.Durability, pItem.MaximumDurability));
Send(string.Format(ServerString.STR_GOT_ITEM, pItem.Itemtype.Name));
}
}
Map.RemoveItem(pMapItem, false);
var msg = new MsgMapItem{
DropType = 3,
Identity = pMapItem.Identity,
MapX = pMapItem.MapX,
MapY = pMapItem.MapY
};
Map.SendToRange(msg, pMapItem.MapX, pMapItem.MapY);
msg.DropType = 2;
Map.SendToRange(msg, pMapItem.MapX, pMapItem.MapY);
return true;
}
public
bool PickMapItem(uint idItem)
{
var pMapItem = Map.QueryRole(idItem) as MapItem;
if (pMapItem == null)
return false;
if (GetDistance(pMapItem) > 0) {
Send(ServerString.STR_TARGET_NOT_IN_RANGE);
return false;
}
if (!pMapItem.IsMoney()
&& Inventory.RemainingSpace() <= 0) {
Send(ServerString.STR_INVENTORY_FULL);
return false;
}
uint idOwner = pMapItem.GetPlayerId();
if (pMapItem.IsPriv() && idOwner != Identity) {
var pOwner = Map.QueryRole(idOwner) as Character;
if (pOwner != null && !IsMate(pOwner)) {
if (Team != null && Team.IsTeamMember(pOwner)) {
if ((pMapItem.IsMoney() && Team.IsCloseMoney) || ((pMapItem.Type == SpecialItem.TYPE_DRAGONBALL || pMapItem.Type == SpecialItem.TYPE_METEOR) && Team.IsCloseGem)
|| (!pMapItem.IsMoney() && pMapItem.Type != SpecialItem.TYPE_DRAGONBALL && pMapItem.Type != SpecialItem.TYPE_METEOR && Team.IsCloseItem)) {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
else {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
else if (pOwner != null && pOwner != this) {
Send(ServerString.STR_CANT_PICKUP_OTHER_ITEMS);
return false;
}
}
if (pMapItem.IsMoney()) {
AwardMoney(pMapItem.GetAmount());
if (pMapItem.GetAmount() > 1000)
Send(new MsgAction(Identity, pMapItem.GetAmount(), MapX, MapY, GeneralActionType.GET_MONEY));
Send(string.Format(ServerString.STR_PICK_MONEY, pMapItem.GetAmount()));
}
else {
var pItem = pMapItem.GetInfo(this);
if (pItem != null) {
var newItem = new DbItem{
AddLife = pItem.Enchantment,
AddlevelExp = pItem.CompositionProgress,
AntiMonster = 0,
ArtifactExpire = pItem.ArtifactExpire,
ArtifactType = pItem.ArtifactType,
ChkSum = 0,
Color = 3,
Data = pItem.SocketProgress,
Gem1 = (byte)pItem.SocketOne,
Gem2 = (byte)pItem.SocketTwo,
Ident = 0,
Magic1 = (byte)pItem.Effect,
Magic2 = 0,
ReduceDmg = pItem.ReduceDamage,
Plunder = pItem.LockTime,
Specialflag = 0,
Inscribed = 0,
StackAmount = pItem.StackAmount,
RefineryExpire = pItem.RefineryExpire,
RefineryLevel = pItem.RefineryLevel,
RefineryType = pItem.RefineryType,
Type = pItem.Type,
Position = 0,
PlayerId = 0,
Monopoly = pItem.Monopoly,
Magic3 = pItem.Plus,
Amount = pItem.Durability,
AmountLimit = pItem.MaximumDurability
};
Inventory.Create(newItem);
//Console.WriteLine("////");
//Console.WriteLine(pItem.Durability);
if (pItem.Type == SpecialItem.TYPE_DRAGONBALL
&& Owner.VipLevel >= 2
&& Inventory.ContainsMultiple(SpecialItem.TYPE_DRAGON BALL, SpecialItem.TYPE_DRAGONBALL, 10)) {
Inventory.DeleteMultiple(SpecialItem.TYPE_DRAGONBA LL, SpecialItem.TYPE_DRAGONBALL, 10);
Inventory.Create(SpecialItem.TYPE_DRAGONBALL_SCROL L);
}
if (pItem.Type == SpecialItem.TYPE_METEOR
&& Owner.VipLevel >= 2
&& Inventory.ContainsMultiple(SpecialItem.TYPE_METEOR , SpecialItem.TYPE_METEOR, 10)) {
Inventory.DeleteMultiple(SpecialItem.TYPE_METEOR, SpecialItem.TYPE_METEOR, 10);
Inventory.Create(SpecialItem.TYPE_METEOR_SCROLL);
}
ServerKernel.Log.GmLog("pick_item", string.Format("{0}({1}) pick item:[id={2}, type={3}], dur={4}, max_dur={5}", Name, Identity, pItem.Identity, pItem.Type, pItem.Durability, pItem.MaximumDurability));
Send(string.Format(ServerString.STR_GOT_ITEM, pItem.Itemtype.Name));
}
}
Map.RemoveItem(pMapItem, false);
var msg = new MsgMapItem{
DropType = 3,
Identity = pMapItem.Identity,
MapX = pMapItem.MapX,
MapY = pMapItem.MapY
};
Map.SendToRange(msg, pMapItem.MapX, pMapItem.MapY);
msg.DropType = 2;
Map.SendToRange(msg, pMapItem.MapX, pMapItem.MapY);
return true;
}
This code will prevent showing wrong item durability after level upgrade:
#region 20 - Uplevel
case ItemAction.UPLEV:
{
Item item;
if (pRole.Inventory.Items.TryGetValue(pMsg.Identity, out item))
{
if (item.Durability / 100 < item.MaximumDurability / 100)
{
pRole.Send(ServerString.STR_REPAIR_THEN_UPGRADE);
return;
}
int idNewType = 0;
double nChance = 0.00;
if (!item.GetUpLevelChance((int)item.Type, out nChance, out idNewType))
{
pRole.Send(ServerString.STR_UPGRADE_NOMORE);
return;
}
DbItemtype dbNewType = ServerKernel.Itemtype.Values.FirstOrDefault(x => x.Type == idNewType);
if (dbNewType == null)
{
pRole.Send(ServerString.STR_UPGRADE_NOMORE);
return;
}
if (!pRole.Inventory.ReduceMeteors(1))
{
pRole.Send(ServerString.STR_ITEM_NOT_FOUND);
return;
}
if (Calculations.ChanceCalc((float)nChance))
{
item.Type = (uint)idNewType;
pRole.SendEffect("improveSuc", false);
}
else
{
item.Durability /= 2;
}
if (Calculations.ChanceCalc(1f))
{
bool changed = false;
if (item.SocketOne == SocketGem.NO_SOCKET)
{
changed = true;
item.SocketOne = SocketGem.EMPTY_SOCKET;
}
else if (item.SocketTwo == SocketGem.NO_SOCKET)
{
changed = true;
item.SocketTwo = SocketGem.EMPTY_SOCKET;
}
if (changed)
pRole.Send(ServerString.STR_IMPROVE_UPGRADE_SOCKET );
}
item.Durability = item.MaximumDurability;
item.Save();
pRole.Send(item.InformationPacket(true));
ServerKernel.Log.GmLog("Upgrade", string.Format("User[{0}] item [{1}] type [{2}] nChance[{3}] used[{4}]", pRole.Identity, item.Identity, item.Type, nChance, SpecialItem.TYPE_DRAGONBALL));
}
break;
}
#endregion
case ItemAction.UPLEV:
{
Item item;
if (pRole.Inventory.Items.TryGetValue(pMsg.Identity, out item))
{
if (item.Durability / 100 < item.MaximumDurability / 100)
{
pRole.Send(ServerString.STR_REPAIR_THEN_UPGRADE);
return;
}
int idNewType = 0;
double nChance = 0.00;
if (!item.GetUpLevelChance((int)item.Type, out nChance, out idNewType))
{
pRole.Send(ServerString.STR_UPGRADE_NOMORE);
return;
}
DbItemtype dbNewType = ServerKernel.Itemtype.Values.FirstOrDefault(x => x.Type == idNewType);
if (dbNewType == null)
{
pRole.Send(ServerString.STR_UPGRADE_NOMORE);
return;
}
if (!pRole.Inventory.ReduceMeteors(1))
{
pRole.Send(ServerString.STR_ITEM_NOT_FOUND);
return;
}
if (Calculations.ChanceCalc((float)nChance))
{
item.Type = (uint)idNewType;
pRole.SendEffect("improveSuc", false);
}
else
{
item.Durability /= 2;
}
if (Calculations.ChanceCalc(1f))
{
bool changed = false;
if (item.SocketOne == SocketGem.NO_SOCKET)
{
changed = true;
item.SocketOne = SocketGem.EMPTY_SOCKET;
}
else if (item.SocketTwo == SocketGem.NO_SOCKET)
{
changed = true;
item.SocketTwo = SocketGem.EMPTY_SOCKET;
}
if (changed)
pRole.Send(ServerString.STR_IMPROVE_UPGRADE_SOCKET );
}
item.Durability = item.MaximumDurability;
item.Save();
pRole.Send(item.InformationPacket(true));
ServerKernel.Log.GmLog("Upgrade", string.Format("User[{0}] item [{1}] type [{2}] nChance[{3}] used[{4}]", pRole.Identity, item.Identity, item.Type, nChance, SpecialItem.TYPE_DRAGONBALL));
}
break;
}
#endregion