-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Pixel-Tactics/refactor/structure
refactor: change match folder structure
- Loading branch information
Showing
29 changed files
with
551 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package matches_actions | ||
|
||
import ( | ||
"errors" | ||
|
||
matches_algorithms "pixeltactics.com/match/src/matches/algorithms" | ||
matches_constants "pixeltactics.com/match/src/matches/constants" | ||
matches_interfaces "pixeltactics.com/match/src/matches/interfaces" | ||
) | ||
|
||
type AttackLog struct { | ||
srcHero matches_interfaces.IHero | ||
trgHero matches_interfaces.IHero | ||
damage int | ||
} | ||
|
||
type AttackLogData struct { | ||
HeroName string `json:"heroName"` | ||
PlayerId string `json:"playerId"` | ||
TargetName string `json:"targetName"` | ||
} | ||
|
||
func (log *AttackLog) Apply(session matches_interfaces.ISession) error { | ||
if !log.srcHero.CanAttack() { | ||
return errors.New("hero cannot attack") | ||
} | ||
|
||
attackRange := log.srcHero.GetBaseStats().AttackRange | ||
damage := log.srcHero.GetBaseStats().Damage | ||
|
||
dist, err := matches_algorithms.CheckDistance(session.GetMatchMap().Structure, log.srcHero.GetPos(), log.trgHero.GetPos()) | ||
if dist > attackRange || err != nil { | ||
return errors.New("target out of range") | ||
} | ||
|
||
log.damage = damage | ||
log.srcHero.SetLastAttackTurn(session.GetCurrentTurn()) | ||
log.trgHero.SetHealth(max(log.trgHero.GetHealth()-damage, 0)) | ||
return nil | ||
} | ||
|
||
func (log *AttackLog) GetSourcePlayerId() string { | ||
return log.srcHero.GetPlayer().GetId() | ||
} | ||
|
||
func (log *AttackLog) GetData() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"hero": log.srcHero.GetName(), | ||
"target": log.trgHero.GetName(), | ||
"playerId": log.srcHero.GetPlayer().GetId(), | ||
"damage": log.damage, | ||
} | ||
} | ||
|
||
func (log *AttackLog) GetName() string { | ||
return matches_constants.ATTACK_LOG | ||
} | ||
|
||
func (log *AttackLog) GetSourceHero() matches_interfaces.IHero { | ||
return log.srcHero | ||
} | ||
|
||
func NewAttackLog(srcHero matches_interfaces.IHero, trgHero matches_interfaces.IHero) *AttackLog { | ||
return &AttackLog{ | ||
srcHero: srcHero, | ||
trgHero: trgHero, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package matches_actions | ||
|
||
import ( | ||
"errors" | ||
|
||
"pixeltactics.com/match/src/exceptions" | ||
matches_interfaces "pixeltactics.com/match/src/matches/interfaces" | ||
matches_physics "pixeltactics.com/match/src/matches/physics" | ||
) | ||
|
||
type MoveLog struct { | ||
srcHero matches_interfaces.IHero | ||
directionList []string | ||
} | ||
|
||
type MoveLogData struct { | ||
HeroName string `json:"heroName"` | ||
PlayerId string `json:"playerId"` | ||
DirectionList []string `json:"directionList"` | ||
} | ||
|
||
func (log *MoveLog) Apply(session matches_interfaces.ISession) error { | ||
if !log.srcHero.CanMove() { | ||
return errors.New("hero already moved this turn") | ||
} | ||
|
||
if log.srcHero.GetHealth() == 0 { | ||
return exceptions.HeroIsDead() | ||
} | ||
|
||
if len(log.directionList) > log.srcHero.GetBaseStats().MoveRange { | ||
return errors.New("invalid movement range") | ||
} | ||
|
||
curPos := log.srcHero.GetPos() | ||
for _, dir := range log.directionList { | ||
dirPoint := matches_physics.GetPointFromDirection(dir) | ||
curPos = curPos.Add(dirPoint) | ||
if !session.IsPointOpen(curPos) { | ||
return errors.New("point is occupied") | ||
} | ||
} | ||
|
||
log.srcHero.SetPos(curPos) | ||
log.srcHero.SetLastMoveTurn(session.GetCurrentTurn()) | ||
return nil | ||
} | ||
|
||
func (log *MoveLog) GetSourcePlayerId() string { | ||
return log.srcHero.GetPlayer().GetId() | ||
} | ||
|
||
func (log *MoveLog) GetData() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"hero": log.srcHero.GetName(), | ||
"playerId": log.srcHero.GetPlayer().GetId(), | ||
"directionList": log.directionList, | ||
} | ||
} | ||
|
||
func (log *MoveLog) GetName() string { | ||
return "move" | ||
} | ||
|
||
func (log *MoveLog) GetSourceHero() matches_interfaces.IHero { | ||
return log.srcHero | ||
} | ||
|
||
func NewMoveLog(hero matches_interfaces.IHero, directionList []string) *MoveLog { | ||
return &MoveLog{ | ||
srcHero: hero, | ||
directionList: directionList, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package matches_constants | ||
|
||
const ( | ||
ATTACK_LOG = "attack" | ||
MOVE_LOG = "move" | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.