model

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Overview

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Project OpenMonster Copyright (C) 2020 Kori

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/\>.

Index

Constants

View Source
const (
	ModifierType_Damage = "damage"
	ModifierType_Status = "status"
)
View Source
const (
	MoveAmount int = 4
)

TODO: Move to config file

Variables

View Source
var ItemCache map[string]*item.Base
View Source
var MoveBaseCache map[string]MoveBase
View Source
var NilMoveBase = NewMoveBaseTemplate("Nil", "Placeholder for empty moves", "", 0, 90)
View Source
var SpeciesCache map[string]*Species
View Source
var TraitCache traitCache = make(traitCache)

Functions

func AddTypeMatchup

func AddTypeMatchup(attacker Type, defender Type, effectivity float64)

AddTypeMatchup adds the effectivity of an attacking type against a defending type. If a combination already exists, it will be replaced.

func DefaultGeneticModifierRange added in v0.3.0

func DefaultGeneticModifierRange() (AttributeStat, AttributeStat)

func GetTypeEffectivity

func GetTypeEffectivity(attacker Type, defender ...Type) float64

GetTypeEffectivity returns the effectivity of an attack type against the defending types. If the combination is not listed, a neutral effectivity is assumed. In the case of a dual-type, the individual type combinations will be used to calculate the final effectivity.

Types

type AttributeStat

type AttributeStat int
const MaxGeneticModifier AttributeStat = 25
const MinGeneticModifier AttributeStat = 1

type Attributes

type Attributes struct {
	Health      AttributeStat `json:"health"`
	PhysAttack  AttributeStat `json:"physAttack"`
	PhysDefense AttributeStat `json:"physDefense"`
	SpecAttack  AttributeStat `json:"specAttack"`
	SpecDefense AttributeStat `json:"specDefense"`
	Initiative  AttributeStat `json:"initiative"`
	Stamina     AttributeStat `json:"stamina"`
}

func (Attributes) Abs added in v0.2.0

func (a Attributes) Abs() Attributes

func (Attributes) Add

func (a Attributes) Add(b Attributes) Attributes

func (Attributes) AddF added in v0.2.0

func (a Attributes) AddF(b float64) Attributes

func (Attributes) AddI added in v0.2.0

func (a Attributes) AddI(b int) Attributes

func (Attributes) Div added in v0.2.0

func (a Attributes) Div(b Attributes) Attributes

func (Attributes) Mult added in v0.2.0

func (a Attributes) Mult(b Attributes) Attributes

func (Attributes) MultF added in v0.2.0

func (a Attributes) MultF(b float64) Attributes

func (Attributes) MultI added in v0.2.0

func (a Attributes) MultI(b int) Attributes

func (Attributes) Pow added in v0.2.0

func (a Attributes) Pow(b Attributes) Attributes

func (Attributes) Sign added in v0.2.0

func (a Attributes) Sign() Attributes

type Breeder

type Breeder struct {
	ID   ID        `json:"id"`
	Name string    `json:"name"`
	Team []Monster `json:"-"`
}

type Condition

type Condition interface {
	Type() string
	IsFulfilled(m Monster) bool
}

type DamageModifier

type DamageModifier struct {
	Power       uint   `json:"power"`
	AttackStat  string `json:"attackStat"`
	DefenseStat string `json:"defenseStat"`
}

func (DamageModifier) MarshalJSON

func (d DamageModifier) MarshalJSON() ([]byte, error)

func (DamageModifier) ModifierType

func (d DamageModifier) ModifierType() string

type EvolveRequirement

type EvolveRequirement Requirement

type Exp

type Exp uint32

type ExpCurve

type ExpCurve struct {
	Name  string          `json:"name"`
	Curve func(Exp) Level `json:"-"`
}

func (*ExpCurve) MarshalJSON

func (ec *ExpCurve) MarshalJSON() ([]byte, error)

func (*ExpCurve) UnmarshalJSON

func (ec *ExpCurve) UnmarshalJSON(data []byte) error

type Gender

type Gender byte
const (
	GenderNeutral Gender = iota
	GenderMale
	GenderFemale
)

type GeneticModifierRangeSupplier added in v0.3.0

type GeneticModifierRangeSupplier func() (from AttributeStat, to AttributeStat)

type ID

type ID uint

type IDSupplier

type IDSupplier interface {
	NextID() ID
}

type Level

type Level uint8

type LevelCondition

type LevelCondition struct {
	Level Level `json:"level"`
}

func (LevelCondition) IsFulfilled

func (l LevelCondition) IsFulfilled(m Monster) bool

func (LevelCondition) MarshalJSON

func (lv LevelCondition) MarshalJSON() ([]byte, error)

func (LevelCondition) Type

func (l LevelCondition) Type() string

type LevelRangeSupplier

type LevelRangeSupplier func() (from Level, to Level)

type Monster

type Monster struct {
	ID                  ID `json:"id"`
	Nickname            string
	Level               Level
	Species             *Species `json:"species"`
	TrainingModifier    Attributes
	GeneticModifier     Attributes
	NutritionalModifier Attributes
	Gender              Gender
	Moves               MoveArr
	Exp                 Exp
	OwnerID             ID
	Status              []status.Ailment
	Trait               *Trait
	MonsterVolatile
}

func CreateMonster

func CreateMonster(species *Species, levelRange LevelRangeSupplier, gmRange GeneticModifierRangeSupplier) *Monster

func (*Monster) ApplyStatus

func (mon *Monster) ApplyStatus(name string, amount int) bool

ApplyStatus adds an amount of points to a status threshold. Returns true, if the threshold is reached and the ailment applied.

func (*Monster) Attributes

func (mon *Monster) Attributes() Attributes

func (*Monster) CurrentHPPercent

func (mon *Monster) CurrentHPPercent() float64

func (*Monster) CurrentStaminaPercent

func (mon *Monster) CurrentStaminaPercent() float64

func (*Monster) Damage

func (mon *Monster) Damage(dmg int)

func (*Monster) IsKO

func (mon *Monster) IsKO() bool

func (Monster) MarshalJSON

func (mon Monster) MarshalJSON() ([]byte, error)

func (*Monster) ReduceStamina

func (mon *Monster) ReduceStamina(stamina int)

func (*Monster) String

func (mon *Monster) String() string

func (*Monster) Types

func (mon *Monster) Types() []Type

func (*Monster) UnmarshalJSON

func (mon *Monster) UnmarshalJSON(data []byte) error

type MonsterVolatile

type MonsterVolatile struct {
	TempModifier    Attributes
	CurrentHP       int
	CurrentStamina  int
	StatusThreshold map[string]int
}

type Move

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

func NewMove

func NewMove(base MoveBase) *Move

func (Move) Base

func (m Move) Base() MoveBase

func (*Move) IncreaseCooldown

func (move *Move) IncreaseCooldown()

func (Move) IsReady

func (m Move) IsReady() bool

func (*Move) MarshalJSON

func (m *Move) MarshalJSON() ([]byte, error)

func (*Move) ResetCooldown

func (move *Move) ResetCooldown()

func (Move) String

func (m Move) String() string

type MoveArr

type MoveArr [MoveAmount]*Move

func NewMoveArr

func NewMoveArr() MoveArr

func (MoveArr) Add

func (ma MoveArr) Add(m *Move) (MoveArr, error)

* Add adds a move to the MoveArr if there is space left and the move is not already in the MoveArr Returns an error, if the move was not added

func (MoveArr) Contains

func (ma MoveArr) Contains(mb MoveBase) bool

* Contains checks, if there is a move with the given MoveBase in the MoveArr

func (MoveArr) MarshalJSON

func (ma MoveArr) MarshalJSON() ([]byte, error)

func (MoveArr) Remove

func (ma MoveArr) Remove(index int) (MoveArr, error)

* Remove removes the move with the given index. Also reorders the moves to remove empty spaces after the move has been removed Returns an error, if it is the last move left or the index is out ouf bounds

type MoveBase

type MoveBase interface {
	Name() string
	Description() string
	Type() Type
	Modifier() []MoveModifier
	StaminaUsage() int
	Cooldown() int
}

type MoveBaseTemplate

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

* MoveBaseTemplate contains the shared information of a move. Everything in MoveBaseTemplate is constant and should not be changed

upgradePoints defines how many points will be added to the move points after an upgrade

func NewMoveBaseTemplate

func NewMoveBaseTemplate(name, description string, moveType Type, staminaUsage int, power uint) *MoveBaseTemplate

func (MoveBaseTemplate) Cooldown

func (mb MoveBaseTemplate) Cooldown() int

func (MoveBaseTemplate) Description

func (mb MoveBaseTemplate) Description() string

func (*MoveBaseTemplate) MarshalJSON

func (mbt *MoveBaseTemplate) MarshalJSON() ([]byte, error)

func (MoveBaseTemplate) Modifier

func (mb MoveBaseTemplate) Modifier() []MoveModifier

func (MoveBaseTemplate) Name

func (mb MoveBaseTemplate) Name() string

func (*MoveBaseTemplate) SetCooldown

func (mb *MoveBaseTemplate) SetCooldown(c int)

func (*MoveBaseTemplate) SetDescription

func (mb *MoveBaseTemplate) SetDescription(desc string)

func (*MoveBaseTemplate) SetModifier

func (mb *MoveBaseTemplate) SetModifier(mod []MoveModifier)

func (*MoveBaseTemplate) SetName

func (mb *MoveBaseTemplate) SetName(name string)

func (*MoveBaseTemplate) SetStaminaUsage

func (mb *MoveBaseTemplate) SetStaminaUsage(su int)

func (*MoveBaseTemplate) SetTarget

func (mb *MoveBaseTemplate) SetTarget(t MoveTarget)

func (*MoveBaseTemplate) SetType

func (mb *MoveBaseTemplate) SetType(t Type)

func (MoveBaseTemplate) StaminaUsage

func (mb MoveBaseTemplate) StaminaUsage() int

func (MoveBaseTemplate) String

func (mb MoveBaseTemplate) String() string

func (MoveBaseTemplate) Target

func (mb MoveBaseTemplate) Target() MoveTarget

func (MoveBaseTemplate) Type

func (mb MoveBaseTemplate) Type() Type

func (*MoveBaseTemplate) UnmarshalJSON

func (mbt *MoveBaseTemplate) UnmarshalJSON(msg []byte) error

type MoveModifier

type MoveModifier interface {
	ModifierType() string
}

type MoveRequirement

type MoveRequirement Requirement

type MoveTarget

type MoveTarget string

type Request

type Request struct {
	ID     ID
	From   ID
	To     ID
	Status RequestStatus
}

type RequestStatus

type RequestStatus string
const (
	ReqStatus_Pending  RequestStatus = "pending"
	ReqStatus_Ok       RequestStatus = "ok"
	ReqStatus_Declined RequestStatus = "declined"
	ReqStatus_Canceled RequestStatus = "canceled"
)

type Requirement

type Requirement struct {
	ID        ID        `json:"id"`
	Name      string    `json:"name"`
	Trigger   string    `json:"trigger"`
	Condition Condition `json:"condition"`
}

func (Requirement) IsFulfilled

func (r Requirement) IsFulfilled(m Monster) bool

func (*Requirement) UnmarshalJSON

func (r *Requirement) UnmarshalJSON(data []byte) error

type Species

type Species struct {
	Name      string        `json:"name"`
	Base      Attributes    `json:"attributeBase"`
	Types     []Type        `json:"types"`
	BaseExp   Exp           `json:"baseExp"`
	ExpCurve  *ExpCurve     `json:"expCurve"`
	MoveSet   []Requirement `json:"moveSet"`
	Evolution []Requirement `json:"evolution"`

	// How many training modifier a monster gains, if it defeats a monster of this species
	TrainingModifier Attributes `json:"trainingModifier"`
}

type StatusModifier

type StatusModifier struct {
	Status string `json:"status"`
	Power  int    `json:"power"`
}

func (StatusModifier) MarshalJSON

func (d StatusModifier) MarshalJSON() ([]byte, error)

func (StatusModifier) ModifierType

func (d StatusModifier) ModifierType() string

type Trait

type Trait struct {
	Name               string  `json:"name"`
	IncreasedAttribute string  `json:"increasedAttribute"`
	DecreasedAttribute string  `json:"decreasedAttribute"`
	IncreasedBy        float64 `json:"increasedBy"`
	DecreasedBy        float64 `json:"decreasedBy"`
}

type Type

type Type string

type Vector2D added in v0.4.0

type Vector2D struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
}

Directories

Path Synopsis
Project OpenMonster Copyright (C) 2020 Kori This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Project OpenMonster Copyright (C) 2020 Kori This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Jump to

Keyboard shortcuts

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