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

hotfix: movement speed penalty attack speed application #196

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Executables/Game/Extensions/ItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
{
return (uint) item.Values[2];
}

public static int GetApplyValue(this ItemData item, EApplyType type)
{
var apply = item.Applies.FirstOrDefault(x => (EApplyType)x.Type == type);

return (int)(apply?.Value ?? 0);
}

/// <summary>
/// Weapon damage added additionally to the base damage
Expand Down Expand Up @@ -117,7 +124,7 @@
}

var item = await repository.GetItemAsync(id);
await cacheManager.Server.Set(key, item);

Check warning on line 127 in src/Executables/Game/Extensions/ItemExtensions.cs

View workflow job for this annotation

GitHub Actions / Test deployment

Possible null reference argument for parameter 'item' in 'ValueTask<string> IRedisStore.Set(string key, object item)'.
return item;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Executables/Game/PlayerConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
public static class PlayerConstants
{
public const int MAX_PLAYERS_PER_ACCOUNT = 4;

public const byte DEFAULT_ATTACK_SPEED = 95;
public const byte DEFAULT_MOVEMENT_SPEED = 150;
}
1 change: 1 addition & 0 deletions src/Executables/Game/World/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public bool PositionChanged
public int StartPositionY { get; private set; }
public uint MovementDuration { get; private set; }
public byte MovementSpeed { get; protected set; }
public byte AttackSpeed { get; protected set; }

public IReadOnlyCollection<IEntity> NearbyEntities => _nearbyEntities;
private readonly List<IEntity> _nearbyEntities = new();
Expand Down
41 changes: 28 additions & 13 deletions src/Executables/Game/World/Entities/PlayerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ public EAntiFlags AntiFlagGender
}
}

private byte _attackSpeed = 140;
private uint _defence;
private byte _minMovespeed = 20;
private byte _maxMovespeed = byte.MaxValue;

private const int PersistInterval = 30 * 1000; // 30s
private int _persistTime = 0;
Expand Down Expand Up @@ -141,7 +138,8 @@ public PlayerEntity(PlayerData player, IGameConnection connection, IItemManager
_scope.ServiceProvider.GetRequiredService<IOptions<GameOptions>>().Value.Skills
);

MovementSpeed = 150;
MovementSpeed = PlayerConstants.DEFAULT_MOVEMENT_SPEED;
AttackSpeed = PlayerConstants.DEFAULT_ATTACK_SPEED;
EntityClass = player.PlayerClass;

Groups = new List<Guid>();
Expand Down Expand Up @@ -183,6 +181,7 @@ public async Task Load()

CalculateDefence();
CalculateMovement();
CalculateAttackSpeed();
}

public async Task ReloadPermissions()
Expand Down Expand Up @@ -274,7 +273,7 @@ private void CalculateDefence()

private void CalculateMovement()
{
MovementSpeed = 150;
MovementSpeed = PlayerConstants.DEFAULT_MOVEMENT_SPEED;
float modifier = 0;
foreach (var slot in Enum.GetValues<EquipmentSlots>())
{
Expand All @@ -283,14 +282,28 @@ private void CalculateMovement()
var proto = _itemManager.GetItem(item.ItemId);
if (proto?.Type != (byte)EItemType.Armor) continue;

var moveSpeedFromItem = proto.Applies.FirstOrDefault(apply => apply.Type == (byte)EApplyType.MovSpeed);
if (moveSpeedFromItem is null) continue;
modifier += (byte)proto.Applies[0].Value;
modifier += proto.GetApplyValue(EApplyType.MovSpeed);
}
var calculatedSpeed = MovementSpeed * (1 + modifier / 100);

MovementSpeed = (byte) Math.Clamp((MovementSpeed * (1+(modifier/100))), _minMovespeed, _maxMovespeed);
MovementSpeed = (byte) Math.Min(calculatedSpeed, byte.MaxValue);
_logger.LogDebug("Calculate Movement value for {Name}, result: {MovementSpeed}", Name, MovementSpeed);
}

private void CalculateAttackSpeed()
{
AttackSpeed = PlayerConstants.DEFAULT_ATTACK_SPEED;
float modifier = 0;
foreach (var slot in Enum.GetValues<EquipmentSlots>())
{
var item = Inventory.EquipmentWindow.GetItem(slot);
if (item == null) continue;
var proto = _itemManager.GetItem(item.ItemId);
if (proto == null) continue;

modifier += proto.GetApplyValue(EApplyType.AttackSpeed);
}
AttackSpeed = (byte) Math.Min(AttackSpeed * (1 + modifier / 100), byte.MaxValue);
}

public override void Die()
Expand Down Expand Up @@ -715,9 +728,9 @@ public override uint GetPoint(EPoints point)
case EPoints.Iq:
return Player.Iq;
case EPoints.AttackSpeed:
return _attackSpeed;
return AttackSpeed;
case EPoints.MoveSpeed:
return this.MovementSpeed;
return MovementSpeed;
case EPoints.Gold:
return Player.Gold;
case EPoints.MinWeaponDamage:
Expand Down Expand Up @@ -1043,6 +1056,7 @@ public void RemoveItem(ItemInstance item)
Inventory.EquipmentWindow.RemoveItem(item);
CalculateDefence();
CalculateMovement();
CalculateAttackSpeed();
SendCharacterUpdate();
SendPoints();
}
Expand Down Expand Up @@ -1070,6 +1084,7 @@ public void SetItem(ItemInstance item, byte window, ushort position)
item.Set(_cacheManager, Player.Id, window, position, _itemRepository).Wait(); // TODO
CalculateDefence();
CalculateMovement();
CalculateAttackSpeed();
SendCharacterUpdate();
SendPoints();
}
Expand Down Expand Up @@ -1170,7 +1185,7 @@ public void SendCharacter(IConnection connection)
PositionY = PositionY,
Class = Player.PlayerClass,
MoveSpeed = MovementSpeed,
AttackSpeed = _attackSpeed
AttackSpeed = AttackSpeed
});
}

Expand Down Expand Up @@ -1204,7 +1219,7 @@ public void SendCharacterUpdate()
(ushort) (Inventory.EquipmentWindow.Hair?.ItemId ?? 0)
},
MoveSpeed = MovementSpeed,
AttackSpeed = _attackSpeed
AttackSpeed = AttackSpeed,
};

Connection.Send(packet);
Expand Down
Loading