battle

package
v0.0.0-...-1af4f67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Width is count of cells in horizontal direction
	Width = 51
	// Height is count of cells in vertical direction
	Height = 5
)

battlefield dimensions

View Source
const (
	Rabbit = iota + 1
	Hedgehog
	Squirrel
	Cat
)

characters

View Source
const CharactersCount = Cat

CharactersCount is total number of characters

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor interface {
	Animate
	// contains filtered or unexported methods
}

Actor is a "manifestation" of a user limited to a battlefield: it can move, eat food, take things and so on

type Actor1

type Actor1 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Actor1 (ID=4) is an Actor for aggressors

type Actor2

type Actor2 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Actor2 (ID=5) is an Actor for defenders

type Animate

type Animate interface {
	Movable
	// contains filtered or unexported methods
}

Animate is a common interface for animated objects, like actors or wolves

type Antidote

type Antidote struct {
	// contains filtered or unexported fields
}

Antidote (ID=43) is an object that provides the persistence to poison food for 10 steps (by default). Note that taking this object by Actors will consume it

type AntidoteThing

type AntidoteThing struct {
	// contains filtered or unexported fields
}

AntidoteThing (ID=35) is a Thing that can be emplaced with a bottle of Antidote (ID=43)

type Apple

type Apple struct {
	// contains filtered or unexported fields
}

Apple (ID=16) is common food: all characters can safely consume these objects

type BatManager

type BatManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BatManager is an implementation of IBattleManager. Both interface and implementation were placed in the same src intentionally! This component is independent.

func (*BatManager) Accept

func (battleMgr *BatManager) Accept(aggressor, defender Sid, char1, char2 byte, aggAbilities, defAbilities []byte,
	levelnames []string, wins byte, quickBattle, removeCall bool) (box *MailBox, err *Error)

Accept confirms the Defender's will to fight against the Aggressor that had initiated the attack by calling "Attack" method some time ago. If the Aggressor cancelled its intention, or timeout happened, this method will do nothing. "aggressor" - Aggressor Session ID "defender" - Defender Session ID "char1" - character of Aggressor (Rabbit, Hedgehog, Squirrel or Cat) "char2" - character of Defender (Rabbit, Hedgehog, Squirrel or Cat) "aggAbilities" - skills and swaggas of Aggressor "defAbilities" - skills and swaggas of Defender "levelnames" - array of level names (ensure that the length is enough! E.g. for wins = 3 this array.size should be 5) "wins" - count of round wins to win the battle "quickBattle" - TRUE for quick battles; this argument does not affect the underlying battle system "removeCall" - TRUE to remove call (for PvP battles)

func (*BatManager) Attack

func (battleMgr *BatManager) Attack(aggressor, defender Sid, aggressorName, defenderName string) (*MailBox, *Error)

Attack initiates the attack. The battle won't be started until a Defender accepts the challenge. "aggressor" - aggressor Session ID "defender" - defender Session ID "aggressorName" - aggressor name "defenderName" - defender name

func (*BatManager) CancelCall

func (battleMgr *BatManager) CancelCall(aggressor Sid) (*MailBox, *Error)

CancelCall discards the call by Aggressor initiative (he just changed his mind to fight). "aggressor" - Aggressor Session ID

func (*BatManager) Close

func (battleMgr *BatManager) Close()

Close shuts IBattleManager down and releases all seized resources

func (*BatManager) DecBattleRefs

func (battleMgr *BatManager) DecBattleRefs()

DecBattleRefs increases a counter of battles utilizations

func (*BatManager) DecFieldRefs

func (battleMgr *BatManager) DecFieldRefs()

DecFieldRefs increases a counter of battlefields utilizations

func (*BatManager) DecRoundRefs

func (battleMgr *BatManager) DecRoundRefs()

DecRoundRefs increases a counter of rounds utilizations

func (*BatManager) GetActorXy

func (battleMgr *BatManager) GetActorXy(sid Sid, actor1 bool) (byte, *Error)

GetActorXy returns a position of an actor on the battlefield. Specify "actor1" = TRUE for Actor1, and "actor1" = FALSE for Actor2. Session ID is needed only to lookup the battle and may be a SID of any participants.

func (*BatManager) GetBattleRefs

func (battleMgr *BatManager) GetBattleRefs() (uint32, uint32)

GetBattleRefs returns count of battles allocations and utilizations. Ideally those 2 numbers should be equal

func (*BatManager) GetBattlesCount

func (battleMgr *BatManager) GetBattlesCount() uint

GetBattlesCount returns current count of battles

func (*BatManager) GetBattlesCountTotal

func (battleMgr *BatManager) GetBattlesCountTotal() uint32

GetBattlesCountTotal returns total count of battles since App startup

func (*BatManager) GetEnvironmentSize

func (battleMgr *BatManager) GetEnvironmentSize() uint

GetEnvironmentSize returns count of battlefields, referenced by the Environment

func (*BatManager) GetFieldRaw

func (battleMgr *BatManager) GetFieldRaw(sid Sid) (raw []byte, e *Error)

GetFieldRaw returns a battlefield as a raw bytearray. Session ID is needed only to lookup the battle and may be a SID of any participants. since 1.3.0

func (*BatManager) GetFieldRefs

func (battleMgr *BatManager) GetFieldRefs() (uint32, uint32)

GetFieldRefs returns count of battlefields allocations and utilizations. Ideally those 2 numbers should be equal

func (*BatManager) GetMovablesDump

func (battleMgr *BatManager) GetMovablesDump(sid Sid) (dump []byte, e *Error)

GetMovablesDump returns a binary dump of all Movable objects on the battlefield: actors, wolves, food, things, etc. Session ID is needed only to lookup the battle and may be a SID of any participants. since 1.3.0

func (*BatManager) GetRoundRefs

func (battleMgr *BatManager) GetRoundRefs() (uint32, uint32)

GetRoundRefs returns count of rounds allocations and utilizations. Ideally those 2 numbers should be equal

func (*BatManager) GiveUp

func (battleMgr *BatManager) GiveUp(sid Sid) (Sid, *MailBox, *Error)

GiveUp is a method to surrender. It means that the battle will be over, and the opponent will become the winner "sid" - coward's Session ID

func (*BatManager) IncBattleRefs

func (battleMgr *BatManager) IncBattleRefs()

IncBattleRefs increases a counter of battles allocations

func (*BatManager) IncFieldRefs

func (battleMgr *BatManager) IncFieldRefs()

IncFieldRefs increases a counter of battlefields allocations

func (*BatManager) IncRoundRefs

func (battleMgr *BatManager) IncRoundRefs()

IncRoundRefs increases a counter of rounds allocations

func (*BatManager) Move

func (battleMgr *BatManager) Move(sid Sid, direction byte) (*MailBox, *Error)

Move performs a single "Move" action for a participant with a Session ID in a given direction

func (*BatManager) Reject

func (battleMgr *BatManager) Reject(aggressor, defender Sid, cowardName string) (box *MailBox, err *Error)

Reject discards the Defender's will to fight against the Aggressor that had initiated the attack by calling "Attack" method some time ago. Aggressor will give the corresponding notification. "aggressor" - Aggressor Session ID "defender" - Defender Session ID "cowardName" - name of a user, who rejected the battle

func (*BatManager) SetController

func (battleMgr *BatManager) SetController(controller IController)

SetController assigns a non-NULL IController for this IBattleManager

func (*BatManager) UseSkill

func (battleMgr *BatManager) UseSkill(sid Sid, skillID byte) (*MailBox, *Error)

UseSkill performs "Use skill" action for a participant with a given Session ID by a given "skillID". This method may produce "Skill not found" error.

func (*BatManager) UseThing

func (battleMgr *BatManager) UseThing(sid Sid) (*MailBox, *Error)

UseThing performs "Use thing" action for a participant with a given Session ID. If an actor hasn't got any things, this method will do nothing

func (*BatManager) WolfExists

func (battleMgr *BatManager) WolfExists(sid Sid, xy byte) (bool, *Error)

WolfExists checks whether a wolf is located in a given position. Session ID is needed only to lookup the battle and may be a SID of any participants.

type Battle

type Battle struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Battle is a struct that represents a single battle

type Beam

type Beam struct {
	// contains filtered or unexported fields
}

Beam (ID=42) is a tool that can be used to build a bridge 3 cells long. Note that taking this object by Actors will consume it, and new 3 chunks will appear instead. IMPORTANT TERMINOLOGY: If a Beam is just established (in vertical position) => it takes only 1 cell, so we call it a "Beam" (ID=42); but when the Beam is converted into a bridge (in horisontal position) => it will take 3 cells, so the original Beam will be destroyed, and 3 new chunks will be created, so we call them "BeamChunks" (ID=15)

type BeamChunk

type BeamChunk struct {
	// contains filtered or unexported fields
}

BeamChunk (ID=15) is a basic single component of bridges (a bridge basically consists of 3 chunks)

type BeamThing

type BeamThing struct {
	// contains filtered or unexported fields
}

BeamThing (ID=34) is a Thing that can be emplaced with a Beam (ID=42).

type Block

type Block struct {
	// contains filtered or unexported fields
}

Block (ID=1) is a solid impassable object that can be used both for bottom and for casual object

type Box

type Box struct {
	// contains filtered or unexported fields
}

Box (ID=47) is a tool that helps Actors to raise a Dais (by default Actors aren't able to raise the Dais) Once established, it will stay up to the end of the round

type BoxThing

type BoxThing struct {
	// contains filtered or unexported fields
}

BoxThing (ID=33) is a Thing that can be emplaced with a Box (ID=47)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder can produce a BeamThing (0x22)

type Carrot

type Carrot struct {
	// contains filtered or unexported fields
}

Carrot (ID=19) is food for Rabbits only; for other characters it's poison

type Cell

type Cell struct {
	sync.RWMutex // to protect objects List
	// contains filtered or unexported fields
}

Cell is a single cell that may contain objects like actors, wolves, things, food, ropes, ladders and so on.

type Dais

type Dais struct {
	// contains filtered or unexported fields
}

Dais (ID=2) is bottom-only object that is impassable (by default) without a Stair (in other words, Dais is a Block, but twice higher)

type Decoration

type Decoration interface {
	IObject
	// contains filtered or unexported methods
}

Decoration is an interface for bells and whistles on the battlefield; they WILL NOT affect the proccess of battle

type DecorationDanger

type DecorationDanger struct {
	// contains filtered or unexported fields
}

DecorationDanger (ID=51) is the same as DecorationWarning, but warns about buried Mines and looks highly aggressive. It is drawn only by a Client, and won't affect the battle mechanics

type DecorationDynamic

type DecorationDynamic struct {
	// contains filtered or unexported fields
}

DecorationDynamic (ID=49) is animated decoration. It is drawn only by a Client, and won't affect the battle mechanics

type DecorationStatic

type DecorationStatic struct {
	// contains filtered or unexported fields
}

DecorationStatic (ID=48) is usual static decoration. It is drawn only by a Client, and won't affect the battle mechanics

type DecorationWarning

type DecorationWarning struct {
	// contains filtered or unexported fields
}

DecorationWarning (ID=50) is decoration like a sign that warns about some danger ahead. It is drawn only by a Client, and won't affect the battle mechanics

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector (ID=46) is a handy tool that deactivates mines N steps ahead (by default N=8). Note that taking this object by Actors will consume it

type DetectorThing

type DetectorThing struct {
	// contains filtered or unexported fields
}

DetectorThing (ID=38) is a Thing that can be emplaced with a mine Detector (ID=46)

type Detractor

type Detractor struct {
	// contains filtered or unexported fields
}

Detractor is an "abstract global" participant of a battle; it is still neither a player, not an actor. There can be exactly 2 instances per Battle

type Emplaced

type Emplaced interface {
	Movable
	// contains filtered or unexported methods
}

Emplaced is an interface for "actual" objects that are established from the Things by demand of an Actor. E.g. when an Actor consumes a MineThing, it is emplaced with a Mine (which means: the Actor buried a Mine) The action of "emplacement" will consume a Thing

type Entry

type Entry interface {
	IObject
	// contains filtered or unexported methods
}

Entry is an "invisible" start point of the Actors where they respawn at the beggining of the battle or after "dying"

type Entry1

type Entry1 struct {
	// contains filtered or unexported fields
}

Entry1 (ID=7) is an entry point for Actor1

type Entry2

type Entry2 struct {
	// contains filtered or unexported fields
}

Entry2 (ID=8) is an entry point for Actor2

type Environment

type Environment struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Environment is "everything reasonable" aside from Actors and AI, e.g. wolves. Please note that this a global singleton object for all battles and all rounds!

type FavouriteFood

type FavouriteFood interface {
	Food
	// contains filtered or unexported methods
}

FavouriteFood is an interface to designate favourite food (this is the virtual food that is replaced on round startup with actual food, e.g. with a Nut for Squirrels, a Carrot for Rabbits and so forth)

type Field

type Field struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Field expresses a single battle field with 2 actors and N wolves (N ≥ 0)

type Flashbang

type Flashbang struct {
	// contains filtered or unexported fields
}

Flashbang (ID=44) is an object that can flash blind the enemy for several seconds. Note that taking this object by Actors will consume it

type FlashbangThing

type FlashbangThing struct {
	// contains filtered or unexported fields
}

FlashbangThing (ID=36) is a Thing that can be emplaced with a FlashBang (ID=44)

type Food

type Food interface {
	Movable
	// contains filtered or unexported methods
}

Food is an interface for all food items: apples, pears, carrots, nuts, etc. These objects are consumed by Actors

type FoodActor1

type FoodActor1 struct {
	// contains filtered or unexported fields
}

FoodActor1 (ID=22) is a FavouriteFood implementation for Actor1

type FoodActor2

type FoodActor2 struct {
	// contains filtered or unexported fields
}

FoodActor2 (ID=23) is a FavouriteFood implementation for Actor2

type Grenadier

type Grenadier struct {
	// contains filtered or unexported fields
}

Grenadier can produce a FlashbangThing (0x24)

type IBattleManager

type IBattleManager interface {
	SetController(controller IController)
	Attack(aggressor, defender Sid, aggressorName, defenderName string) (*MailBox, *Error)
	Accept(aggressor, defender Sid, char1, char2 byte, aggAbilities, defAbilities []byte, levelnames []string,
		wins byte, quickBattle, removeCall bool) (*MailBox, *Error)
	Reject(aggressor, defender Sid, cowardName string) (*MailBox, *Error)
	CancelCall(aggressor Sid) (*MailBox, *Error)
	Move(sid Sid, direction byte) (*MailBox, *Error)
	UseThing(Sid) (*MailBox, *Error)
	UseSkill(sid Sid, skillID byte) (*MailBox, *Error)
	GiveUp(Sid) (enemySid Sid, box *MailBox, e *Error)
	GetActorXy(sid Sid, actor1 bool) (byte, *Error)
	WolfExists(sid Sid, xy byte) (bool, *Error)
	GetFieldRaw(sid Sid) (raw []byte, e *Error)
	GetMovablesDump(sid Sid) (dump []byte, e *Error)
	GetBattlesCount() uint
	GetBattlesCountTotal() uint32
	IncBattleRefs()
	DecBattleRefs()
	GetBattleRefs() (uint32, uint32)
	IncRoundRefs()
	DecRoundRefs()
	GetRoundRefs() (uint32, uint32)
	IncFieldRefs()
	DecFieldRefs()
	GetFieldRefs() (uint32, uint32)
	GetEnvironmentSize() uint
	Close()
	// contains filtered or unexported methods
}

IBattleManager is an interface for all battle management operations

func NewBattleManager

func NewBattleManager(reader *filereader.FileReader, packer IPacker, ctrl IController) IBattleManager

NewBattleManager creates a new instance of BattleManager and returns a reference to IBattleManager interface. Please do not create a BatManager directly. "reader" - file reader "packer" - reference to IPacker implementation "ctrl" - reference to IController implementation

type IController

type IController interface {
	Event(*MailBox, *Error)
	GameOver(winnerSid, loserSid Sid, score1, score2 byte, quickBattle bool, box *MailBox) (reward uint32, err *Error)
}

IController contains methods for IBattleManager callbacks

type IObject

type IObject interface {
	// contains filtered or unexported methods
}

IObject is a base interface for ALL objects, like Apples, Pears, Actors, Wolves, Blocks, Umbrellas and so on

type IPacker

type IPacker interface {
	PackCall(aggressor Sid, aggressorName string) []byte
	PackStopCallRejected(cowardName string) []byte
	PackStopCallMissed(aggressorName string) []byte
	PackStopCallExpired(defenderName string) []byte
	PackFullState(state []byte) []byte
	PackRoundInfo(sid, aggressor Sid, roundNum, timeSec, char1, char2, myLives, enemyLives byte, fname string) []byte
	PackAbilityList(abilities []byte) []byte
	PackStateChanged(objNum, objID, xy byte, reset bool) []byte
	PackScoreChanged(score1, score2 byte) []byte
	PackEffectChanged(effID byte, added bool, objNumber byte) []byte
	PackWound(sid, woundSid Sid, cause, myLives, enemyLives byte) []byte
	PackThingTaken(sid, ownerSid Sid, thingID byte) []byte
	PackObjectAppended(id, objNum, xy byte) []byte
	PackRoundFinished(sid, winnerSid Sid, totalScore1, totalScore2 byte) []byte
	PackGameOver(sid, winnerSid Sid, totalScore1, totalScore2 byte, reward uint32) []byte
}

IPacker interface comprises of methods for converting some events into a bytearray

type Ladder

type Ladder interface {
	IObject
	// contains filtered or unexported methods
}

Ladder is an interface for ladders: objects that Animated objects can use to move up and down

type LadderBottom

type LadderBottom struct {
	// contains filtered or unexported fields
}

LadderBottom (ID=10) is an object that Animated objects can use to move up

type LadderTop

type LadderTop struct {
	// contains filtered or unexported fields
}

LadderTop (ID=9) is an object that Animated objects can use to move down

type Meat

type Meat struct {
	// contains filtered or unexported fields
}

Meat (ID=18) is food for Cats only; for other characters it's poison

type Mine

type Mine struct {
	// contains filtered or unexported fields
}

Mine (ID=41) is a object that explodes (by default) when Actors step on it. This causes lost of 1 live for Actors. Note that taking this object by Actors will consume it

type MineThing

type MineThing struct {
	// contains filtered or unexported fields
}

MineThing (ID=33) is a Thing that can be emplaced with a Mine (ID=41)

type Miner

type Miner struct {
	// contains filtered or unexported fields
}

Miner can produce a MineThing (0x21)

type Movable

type Movable interface {
	IObject
	// contains filtered or unexported methods
}

Movable is an interface for all objects that could disappear (like Things) or change the location (like Actors)

type Mushroom

type Mushroom struct {
	// contains filtered or unexported fields
}

Mushroom (ID=20) is food for Hedgehogs only; for other characters it's poison

type Nut

type Nut struct {
	// contains filtered or unexported fields
}

Nut (ID=21) is food for Squirrels only; for other characters it's poison

type Pear

type Pear struct {
	// contains filtered or unexported fields
}

Pear (ID=17) is common food: all characters can safely consume these objects

type Player

type Player struct {
	// contains filtered or unexported fields
}

Player is a participant of a battle scoped to a single round (new round = new instance of Player). There can be exactly 2 instances of Player per Round

type Raisable

type Raisable interface {
	IObject
	// contains filtered or unexported methods
}

Raisable is a interface for objects that Actors can use to mount a Dais

type RopeLine

type RopeLine struct {
	// contains filtered or unexported fields
}

RopeLine (ID=12) is an object that Animated objects can use to raise up, like with LadderBottom

type Round

type Round struct {
	TryMutex
	// contains filtered or unexported fields
}

Round is a time-restricted single part of the battle (i.e. a Battle consists of N rounds, until one of Players reaches specific count of wins)

type Shaman

type Shaman struct {
	// contains filtered or unexported fields
}

Shaman can produce a AntidoteThing (0x23)

type Skill

type Skill interface {
	// contains filtered or unexported methods
}

Skill is a consumable ability: an actor can convert it into a thing (the Skill will disappear until next round)

type Solid

type Solid interface {
	IObject
	// contains filtered or unexported methods
}

Solid is an interface for solid objects like Block, Dais or BeamChunk

type Stair

type Stair struct {
	// contains filtered or unexported fields
}

Stair (ID=11) is an artificial object that Actors can use to mount a Dais

type Swagga

type Swagga int

Swagga is a non-consumable ability: an actor just can put it on and take advantage of it all the time

const (
	Snorkel Swagga = 1 + iota
	ClimbingShoes
	SouthWester
	VoodooMask
	SapperShoes
	Sunglasses
)

Swagga constants

type Teleport

type Teleport struct {
	// contains filtered or unexported fields
}

Teleport (ID=45) is a special tool that relocates Actors to the mirrored (by default) cell on the battlefield. Note that taking this object by Actors will consume it

type TeleportMan

type TeleportMan struct {
	// contains filtered or unexported fields
}

TeleportMan can produce a TeleportThing (0x25)

type TeleportThing

type TeleportThing struct {
	// contains filtered or unexported fields
}

TeleportThing (ID=37) is a Thing that can be emplaced with a Teleport (ID=45)

type Thing

type Thing interface {
	Movable
	// contains filtered or unexported methods
}

Thing is an interface for items, that can be picked up by Actors and then converted into actual handy objects on the battlefield, e.g. an UmbrellaThing can be emplaced with an Umbrella to keep an Actor safe from Waterfalls. The action of "emplacement" will consume a Thing

type Umbrella

type Umbrella struct {
	// contains filtered or unexported fields
}

Umbrella (ID=40) is a tool to protect Actors from Waterfalls. Once established, it will stay up to the end of the round

type UmbrellaThing

type UmbrellaThing struct {
	// contains filtered or unexported fields
}

UmbrellaThing (ID=32) is a Thing that can be emplaced with an Umbrella (ID=40)

type Water

type Water struct {
	// contains filtered or unexported fields
}

Water (ID=3) is a non-solid object that can be used both for bottom and for casual object. By default, wolves can pass the Water bottom, whilst actors - can't

type Waterfall

type Waterfall struct {
	// contains filtered or unexported fields
}

Waterfall (ID=13) is an object that may hurt Actors (by default), and can be passed by with an Umbrella

type WaterfallSafe

type WaterfallSafe struct {
	// contains filtered or unexported fields
}

WaterfallSafe (ID=14) is the same as Waterfall, but doesn't hurt Actors. Used primarily for education purposes deprecated since 1.3.10, but kept for backward campatibility

type Wolf

type Wolf struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Wolf (ID=6) is an animated object that "chases" the actors; there may be several wolves on the battle field

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL