NetworkSession: allow sending an arbitrary set of attributes for an entity

This commit is contained in:
Dylan K. Taylor
2020-04-29 16:45:09 +01:00
parent f6f714c158
commit d1b28ce17a
3 changed files with 10 additions and 7 deletions

View File

@@ -680,12 +680,14 @@ class NetworkSession{
$this->sendDataPacket($pk);
}
public function syncAttributes(Living $entity, bool $sendAll = false) : void{
$entries = $sendAll ? $entity->getAttributeMap()->getAll() : $entity->getAttributeMap()->needSend();
if(count($entries) > 0){
/**
* @param Attribute[] $attributes
*/
public function syncAttributes(Living $entity, array $attributes) : void{
if(count($attributes) > 0){
$this->sendDataPacket(UpdateAttributesPacket::create($entity->getId(), array_map(function(Attribute $attr) : NetworkAttribute{
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
}, $entries)));
}, $attributes)));
}
}