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

add fairy enum #70

Merged
merged 2 commits into from
Oct 13, 2023
Merged
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
61 changes: 61 additions & 0 deletions apps/elven_data/lib/elven_data/enums/entity_enums.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ElvenData.Enums.EntityEnums do
# Type portal is unknown yet
defenum :entity_type, player: 1, npc: 2, monster: 3, map_object: 9, portal: 1000
defenum :element_type, [:neutral, :fire, :water, :light, :darkness]
defenum :fairy_move_type, static: 1, circle: 2, slow_circle: 3, big_circle: 4

defenum :direction_type, [
:north,
Expand All @@ -19,4 +20,64 @@ defmodule ElvenData.Enums.EntityEnums do
:south_west,
:north_west
]

defenum :fairy_morph_type, [
:default,
:dancing_chicky,
:little_chick,
:grumbly_chicky,
:solaris,
:sellaim,
:woondine,
:eperial,
:turik,
:azuris,
:sellaim_boosted,
:woondine_boosted,
:eperial_boosted,
:turik_boosted,
:red_magical,
:princess,
:no_element,
:no_element_2,
:no_element_3,
:no_element_4,
:default_2,
:mini_sellaim,
:mini_woondine,
:mini_eperial,
:mini_turik,
:mini_princess,
:mini_sellaim_boosted,
:mini_woondine_boosted,
:mini_eperial_boosted,
:mini_turik_boosted,
:default_3,
:mini_sellaim_2,
:mini_woondine_2,
:mini_eperial_2,
:mini_turik_2,
:mini_princess_2,
:medium_sellaim_boosted,
:medium_woondine_boosted,
:medium_eperial_boosted,
:medium_turik_boosted,
:elkaim,
:ladine,
:rumial,
:varik,
:no_element_5,
:elkaim_boosted,
:ladine_boosted,
:rumial_boosted,
:varik_boosted,
:zenas,
:erenia,
:fernon,
:no_element_6,
:no_element_7,
:zenas_boosted,
:erenia_boosted,
:fernon_boosted
]
end
2 changes: 2 additions & 0 deletions apps/elven_data/test/elven_data/enums/entity_enums_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ defmodule ElvenViews.EntityEnumsTest do
test_enum EntityEnums, :entity_type
test_enum EntityEnums, :element_type
test_enum EntityEnums, :direction_type
test_enum EntityEnums, :fairy_move_type
test_enum EntityEnums, :fairy_morph_type
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defmodule ElvenPackets.Server.VisibilityPackets do
only: [
entity_type: 1,
element_type: 1,
direction_type: 1
direction_type: 1,
fairy_move_type: 1,
fairy_morph_type: 1
]

import ElvenData.Enums.MapEnums, only: [spawn_effect_type: 1]
Expand Down Expand Up @@ -54,10 +56,10 @@ defmodule ElvenPackets.Server.VisibilityPackets do
field :mp_percent, NsInteger
field :is_sitting, NsBoolean
field :group_id, NsInteger
field :fairy_move_type_id, NsInteger
field :fairy_move, NsEnum, values: fairy_move_type(:__enumerators__), default: :big_circle
field :fairy_element, NsEnum, values: element_type(:__enumerators__)
field :unknown1, NsInteger, default: 0
field :fairy_morph, NsInteger
field :fairy_morph, NsEnum, values: fairy_morph_type(:__enumerators__)
field :spawn_effect, NsEnum, values: spawn_effect_type(:__enumerators__), default: :summon
field :morph, NsEnum, default: :default, values: morph(:__enumerators__)
field :weapon_upgrade, UpgradeRarity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule ElvenPackets.Views.VisibilityViews do
mp_percent: mp_percent,
is_sitting: PlayerBundle.sitting?(entity),
group_id: PlayerBundle.group_id(entity),
fairy_move_type_id: PlayerBundle.fairy_move_type_id(entity),
fairy_move: PlayerBundle.fairy_move(entity),
fairy_element: PlayerBundle.fairy_element(entity),
fairy_morph: PlayerBundle.fairy_morph(entity),
spawn_effect: spawn_effect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule ElvenPackets.ServerPackets.VisibilityPacketsTest do
assert Enum.at(params, 15) == "0"
# field :group_id
assert Enum.at(params, 16) == "9999"
# field :fairy_move_type_id
# field :fairy_move
assert Enum.at(params, 17) == "1"
# field :fairy_element
assert Enum.at(params, 18) == "3"
Expand Down Expand Up @@ -147,9 +147,9 @@ defmodule ElvenPackets.ServerPackets.VisibilityPacketsTest do
mp_percent: 60,
is_sitting: false,
group_id: 9999,
fairy_move_type_id: 1,
fairy_move: :static,
fairy_element: :light,
fairy_morph: 42,
fairy_morph: :rumial,
spawn_effect: :falling,
morph: :demon_hunter,
weapon_upgrade: weapon_upgrade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ defmodule ElvenPackets.Views.VisibilityViewsTest do
assert packet.mp_percent == 90
assert packet.is_sitting == false
assert packet.group_id == -1
assert packet.fairy_move_type_id == -1
assert packet.fairy_move == nil
assert packet.fairy_element == :neutral
assert packet.fairy_morph == -1
assert packet.fairy_morph == nil
assert packet.spawn_effect == :summon
assert packet.morph == :default
assert packet.weapon_upgrade == %UpgradeRarity{upgrade: 0, rarity: 0}
Expand All @@ -65,6 +65,21 @@ defmodule ElvenPackets.Views.VisibilityViewsTest do
assert packet.hero_level == 79
assert packet.title_id == 10
end

test "serialization for players with a fairy" do
fairy = %P.FairyComponent{
type: :rumial,
move_type: :static,
element: :fire
}

args = %{entity: new_player(fairy: fairy)}
packet = VisibilityViews.render(:in, args)

assert packet.fairy_move == :static
assert packet.fairy_element == :fire
assert packet.fairy_morph == :rumial
end
end

describe "out" do
Expand Down
9 changes: 6 additions & 3 deletions apps/elven_packets/test/support/view_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ defmodule ElvenPackets.ViewCase do

using do
quote do
import unquote(__MODULE__), only: [new_player: 0]
import unquote(__MODULE__), only: [new_player: 0, new_player: 1]

alias GameService.EntityComponents, as: E
alias GameService.PlayerComponents, as: P
end
end

## Helpers

def new_player(attrs \\ %{}) do
def new_player(attrs \\ []) do
%PlayerBundle{
id: Enum.random(1..100_000),
# Basics components
Expand Down Expand Up @@ -47,7 +50,7 @@ defmodule ElvenPackets.ViewCase do
cannot_attack: nil,
cannot_move: nil
}
|> Map.merge(attrs)
|> Map.merge(Map.new(attrs))
end

defp account_component() do
Expand Down
8 changes: 3 additions & 5 deletions apps/game_service/lib/game_service/bundles/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,15 @@ defmodule GameService.PlayerBundle do
def fairy_morph(%PlayerBundle{} = player) do
case player.fairy do
:unset -> raise ArgumentError, "you must fetch the Player.FairyComponent first"
# FIXME: Not sure about the default value
nil -> -1
nil -> nil
fairy -> fairy.type
end
end

def fairy_move_type_id(%PlayerBundle{} = player) do
def fairy_move(%PlayerBundle{} = player) do
case player.fairy do
:unset -> raise ArgumentError, "you must fetch the Player.FairyComponent first"
# FIXME: Not sure about the default value
nil -> -1
nil -> nil
fairy -> fairy.move_type
end
end
Expand Down
Loading