Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements GameAction/Event for Update Health #172

Merged
merged 4 commits into from
Mar 28, 2017

Conversation

Lidefeath
Copy link
Contributor

This is limited for Players currently but should be adjustable once creatures are in.

if (objectId.IsPlayer())
{
var tmpLandblock = this.Session.Player.Position.LandblockId;
var pl = (Player)LandblockManager.GetObjectByGuid(tmpLandblock, objectId);
Copy link
Contributor

@Mogwai-TheFurry Mogwai-TheFurry Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already have the player.... this.Session.Player

There should be next to zero reason to return objects from the Landblock / LandblockManager. That was a red flag to me, and this is the incorrect usage. It's also not safe to extract as the player may cross a landblock boundary while running across the open world.

@@ -52,6 +52,17 @@ public static void RelocateObject(WorldObject worldObject)
}

/// <summary>
/// Find a worldobject by its guid in the specified landblock
/// </summary>
public static WorldObject GetObjectByGuid(LandblockId blockId, ObjectGuid objectId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method. This might be needed eventually, but for now it's a red flag for "you're doing it wrong."

/// <summary>
/// get the WorldObject specified by objectID
/// </summary>
public WorldObject GetWorldObjectByGuid(ObjectGuid objectId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method. This might be needed eventually, but for now it's a red flag for "you're doing it wrong."

…us remove GetObjectByGuid from Landblock and LandblockManager
@Lidefeath
Copy link
Contributor Author

The last commit (b5480f2) has the requested changes

Copy link
Contributor

@Mogwai-TheFurry Mogwai-TheFurry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. 2 minor tweaks is all :)

// check adjacent landblocks for the targetId
foreach (var block in adjacencies)
{
lock (objectCacheLocker)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking, but unfortunately this particular lock isn't going to help you. You're locking THIS landblock's mutex and poking your head into other landblocks. You need to lock block.objectCacheLocker.

}
}
}
float healthPercentage = (float)pl.Health.Current / (float)pl.Health.MaxValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pl can be null at this point, too (player portals off the block). Just a quick null check will prevent exceptions.

@Mogwai-TheFurry Mogwai-TheFurry merged commit 5d1066c into ACEmulator:master Mar 28, 2017
@Lidefeath Lidefeath deleted the UpdateHealth branch April 20, 2017 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants