bqs

package
v0.0.0-...-ab6c4a8 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2018 License: MPL-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ORIENTATION_UP    = 1
	ORIENTATION_DOWN  = 2
	ORIENTATION_LEFT  = 3
	ORIENTATION_RIGTH = 4
)
View Source
const (
	EVENT_HELLO      = 0
	EVENT_WELCOME    = 1
	EVENT_SWAPN      = 2
	EVENT_DESPAWN    = 3
	EVENT_MOVE       = 4
	EVENT_LOOTMOVE   = 5
	EVENT_ATTACk     = 7
	EVENT_HIT        = 8
	EVENT_HURT       = 9
	EVENT_HEALTH     = 10
	EVENT_CHAT       = 11
	EVENT_LOOT       = 12
	EVENT_EQUIP      = 13
	EVENT_DROP       = 14
	EVENT_TELEPORT   = 15
	EVENT_DAMAGE     = 16
	EVENT_POPULATION = 17
	EVENT_KILL       = 18
	EVENT_LIST       = 19
	EVENT_WHO        = 20
	EVENT_ZONE       = 21
	EVENT_DESTROY    = 22
	EVENT_HP         = 23
	EVENT_BLINK      = 24
	EVENT_CHECK      = 26

	EVENT_ADD_ENTITY   = 100
	EVENT_LOGOUT       = 101
	EVENT_ITEM_RESWAPN = 102
	EVENT_ITEM_DESWAPN = 103
	EVENT_MOB_RESWAPN  = 104
	EVENT_MOB_CALM     = 105
)
View Source
const DEFAULT_CONNECT_TIME = 60 * 5
View Source
const DEFAULT_DROP_ITEM_TIME = 5 * time.Second
View Source
const DEFAULT_ITEM_RESWAPN_TIME = 30 * time.Second
View Source
const DEFAULT_MOB_CALM_TIME = 5 * time.Second
View Source
const DEFAULT_MOB_RESWAPN_TIME = 45 * time.Second

Variables

View Source
var (
	TYPE_WARRIOR = EntityType{1, "warrior", "player"}
	// Mobs
	TYPE_RAT         = EntityType{2, "RAT", "mob"}
	TYPE_SKELETON    = EntityType{3, "SKELETON", "mob"}
	TYPE_GOBLIN      = EntityType{4, "GOBLIN", "mob"}
	TYPE_OGRE        = EntityType{5, "OGRE", "mob"}
	TYPE_SPECTRE     = EntityType{6, "SPECTRE", "mob"}
	TYPE_CRAB        = EntityType{7, "CRAB", "mob"}
	TYPE_BAT         = EntityType{8, "BAT", "mob"}
	TYPE_WIZARD      = EntityType{9, "WIZARD", "mob"}
	TYPE_EYE         = EntityType{10, "EYE", "mob"}
	TYPE_SNAKE       = EntityType{11, "SNAKE", "mob"}
	TYPE_SKELETON2   = EntityType{12, "SKELETON2", "mob"}
	TYPE_BOSS        = EntityType{13, "BOSS", "mob"}
	TYPE_DEATHKNIGHT = EntityType{14, "DEATHKNIGHT", "mob"}

	// Weapons
	TYPE_SWORD1      = EntityType{60, "SWORD1", "weapon"}
	TYPE_SWORD2      = EntityType{61, "SWORD2", "weapon"}
	TYPE_REDSWORD    = EntityType{62, "REDSWORD", "weapon"}
	TYPE_GOLDENSWORD = EntityType{63, "GOLDENSWORD", "weapon"}
	TYPE_MORNINGSTAR = EntityType{64, "MORNINGSTAR", "weapon"}
	TYPE_AXE         = EntityType{65, "AXE", "weapon"}
	TYPE_BLUESWORD   = EntityType{66, "BLUESWORD", "weapon"}

	// Armors
	TYPE_FIREFOX      = EntityType{20, "FIREFOX", "armor"}
	TYPE_CLOTHARMOR   = EntityType{21, "CLOTHARMOR", "armor"}
	TYPE_LEATHERARMOR = EntityType{22, "LEATHERARMOR", "armor"}
	TYPE_MAILARMOR    = EntityType{23, "MAILARMOR", "armor"}
	TYPE_PLATEARMOR   = EntityType{24, "PLATEARMOR", "armor"}
	TYPE_REDARMOR     = EntityType{25, "REDARMOR", "armor"}
	TYPE_GOLDENARMOR  = EntityType{26, "GOLDENARMOR", "armor"}

	// Objects
	TYPE_FLASK      = EntityType{35, "FLASK", "object"}
	TYPE_BURGER     = EntityType{36, "BURGER", "object"}
	TYPE_CHEST      = EntityType{37, "CHEST", "object"}
	TYPE_FIREPOTION = EntityType{38, "FIREPOTION", "object"}
	TYPE_CAKE       = EntityType{39, "CAKE", "object"}

	// NPCs
	TYPE_GUARD       = EntityType{40, "GUARD", "npc"}
	TYPE_KING        = EntityType{41, "KING", "npc"}
	TYPE_OCTOCAT     = EntityType{42, "OCTOCAT", "npc"}
	TYPE_VILLAGEGIRL = EntityType{43, "VILLAGEGIRL", "npc"}
	TYPE_VILLAGER    = EntityType{44, "VILLAGER", "npc"}
	TYPE_PRIEST      = EntityType{45, "PRIEST", "npc"}
	TYPE_SCIENTIST   = EntityType{46, "SCIENTIST", "npc"}
	TYPE_AGENT       = EntityType{47, "AGENT", "npc"}
	TYPE_RICK        = EntityType{48, "RICK", "npc"}
	TYPE_NYAN        = EntityType{49, "NYAN", "npc"}
	TYPE_SORCERER    = EntityType{50, "SORCERER", "npc"}
	TYPE_BEACHNPC    = EntityType{51, "BEACHNPC", "npc"}
	TYPE_FORESTNPC   = EntityType{52, "FORESTNPC", "npc"}
	TYPE_DESERTNPC   = EntityType{53, "DESERTNPC", "npc"}
	TYPE_LAVANPC     = EntityType{54, "LAVANPC", "npc"}
	TYPE_CODER       = EntityType{55, "CODER", "npc"}
)
View Source
var EntityTypeMap = map[string]EntityType{
	"rat":       TYPE_RAT,
	"skeleton":  TYPE_SKELETON,
	"skeleton2": TYPE_SKELETON2,
	"goblin":    TYPE_GOBLIN,
	"ogre":      TYPE_OGRE,

	"spectre":     TYPE_SPECTRE,
	"deathknight": TYPE_DEATHKNIGHT,
	"crab":        TYPE_CRAB,
	"snake":       TYPE_SNAKE,
	"bat":         TYPE_BAT,
	"wizard":      TYPE_WIZARD,
	"eye":         TYPE_EYE,
	"boss":        TYPE_BOSS,

	"sword1":      TYPE_SWORD1,
	"sword2":      TYPE_SWORD2,
	"axe":         TYPE_AXE,
	"redsword":    TYPE_REDSWORD,
	"bluesword":   TYPE_BLUESWORD,
	"goldensword": TYPE_GOLDENSWORD,
	"morningstar": TYPE_MORNINGSTAR,

	"firefox":      TYPE_FIREFOX,
	"clotharmor":   TYPE_CLOTHARMOR,
	"leatherarmor": TYPE_LEATHERARMOR,
	"mailarmor":    TYPE_MAILARMOR,
	"platearmor":   TYPE_PLATEARMOR,
	"redarmor":     TYPE_REDARMOR,
	"goldenarmor":  TYPE_GOLDENARMOR,

	"flask":      TYPE_FLASK,
	"cake":       TYPE_CAKE,
	"burger":     TYPE_BURGER,
	"chest":      TYPE_CHEST,
	"firepotion": TYPE_FIREPOTION,

	"guard":       TYPE_GUARD,
	"villagegirl": TYPE_VILLAGEGIRL,
	"villager":    TYPE_VILLAGER,
	"coder":       TYPE_CODER,
	"scientist":   TYPE_SCIENTIST,
	"priest":      TYPE_PRIEST,
	"king":        TYPE_KING,
	"rick":        TYPE_RICK,
	"nyan":        TYPE_NYAN,
	"sorcerer":    TYPE_SORCERER,
	"agent":       TYPE_AGENT,
	"octocat":     TYPE_OCTOCAT,
	"beachnpc":    TYPE_BEACHNPC,
	"forestnpc":   TYPE_FORESTNPC,
	"desertnpc":   TYPE_DESERTNPC,
	"lavanpc":     TYPE_LAVANPC,
}
View Source
var MobPropertiesMap = map[int]*MobProperty{
	TYPE_RAT.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      40,
			"burger":     10,
			"firepotion": 5,
		},
		HP:     25,
		Armor:  1,
		Weapon: 1,
	},
	TYPE_SKELETON.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      40,
			"mailarmor":  10,
			"axe":        20,
			"firepotion": 5,
		},
		HP:     110,
		Armor:  2,
		Weapon: 2,
	},
	TYPE_GOBLIN.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      40,
			"mailarmor":  20,
			"axe":        20,
			"firepotion": 5,
		},
		HP:     19,
		Armor:  2,
		Weapon: 1,
	},
	TYPE_OGRE.Id: &MobProperty{
		Drops: map[string]int{
			"burger":      10,
			"flask":       50,
			"platearmor":  20,
			"morningstar": 20,
			"firepotion":  5,
		},
		HP:     200,
		Armor:  3,
		Weapon: 2,
	},
	TYPE_SPECTRE.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      30,
			"redarmor":   40,
			"redsword":   30,
			"firepotion": 5,
		},
		HP:     250,
		Armor:  2,
		Weapon: 4,
	},
	TYPE_DEATHKNIGHT.Id: &MobProperty{
		Drops: map[string]int{
			"burger":     95,
			"firepotion": 5,
		},
		HP:     250,
		Armor:  3,
		Weapon: 3,
	},
	TYPE_CRAB.Id: &MobProperty{
		Drops: map[string]int{
			"flask":        50,
			"axe":          20,
			"leatherarmor": 10,
			"firepotion":   5,
		},
		HP:     60,
		Armor:  2,
		Weapon: 1,
	},
	TYPE_SNAKE.Id: &MobProperty{
		Drops: map[string]int{
			"flask":       50,
			"mailarmor":   10,
			"morningstar": 10,
			"firepotion":  5,
		},
		HP:     150,
		Armor:  3,
		Weapon: 2,
	},
	TYPE_SKELETON2.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      60,
			"platearmor": 15,
			"bluesword":  15,
			"firepotion": 5,
		},
		HP:     200,
		Armor:  3,
		Weapon: 3,
	},
	TYPE_EYE.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      50,
			"redarmor":   20,
			"redsword":   10,
			"firepotion": 5,
		},
		HP:     200,
		Armor:  3,
		Weapon: 3,
	},
	TYPE_BAT.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      50,
			"axe":        20,
			"firepotion": 5,
		},
		HP:     80,
		Armor:  2,
		Weapon: 1,
	},
	TYPE_WIZARD.Id: &MobProperty{
		Drops: map[string]int{
			"flask":      50,
			"platearmor": 20,
			"firepotion": 5,
		},
		HP:     100,
		Armor:  2,
		Weapon: 6,
	},

	TYPE_BOSS.Id: &MobProperty{
		Drops: map[string]int{
			"goldensword": 100,
		},
		HP:     700,
		Armor:  6,
		Weapon: 7,
	},
}
View Source
var RankedArmors = map[int]int{
	TYPE_CLOTHARMOR.Id:   1,
	TYPE_LEATHERARMOR.Id: 2,
	TYPE_MAILARMOR.Id:    3,
	TYPE_PLATEARMOR.Id:   4,
	TYPE_REDARMOR.Id:     5,
	TYPE_GOLDENARMOR.Id:  6,
}
View Source
var RankedWeapon = map[int]int{
	TYPE_SWORD1.Id:      1,
	TYPE_SWORD2.Id:      2,
	TYPE_AXE.Id:         3,
	TYPE_MORNINGSTAR.Id: 4,
	TYPE_BLUESWORD.Id:   5,
	TYPE_REDSWORD.Id:    6,
	TYPE_GOLDENSWORD.Id: 7,
}

Functions

func DmgFormula

func DmgFormula(weaponLevel, armorLevel int) int

func GetArmorRank

func GetArmorRank(armorId int) int

func GetWeaponRank

func GetWeaponRank(weaponId int) int

func HpFormula

func HpFormula(armorLevel int) int

func IsArmor

func IsArmor(kind EntityType) bool

func IsHealingItem

func IsHealingItem(kind EntityType) bool

func IsItem

func IsItem(kind EntityType) bool

func IsWeapon

func IsWeapon(kind EntityType) bool

func ParseCmd

func ParseCmd(data []byte) (int, *simplejson.Json, error)

func ReleaseEvent

func ReleaseEvent(e *Event)

Types

type Area

type Area struct {
	Id            int
	X, Y          int
	Width, Height int
	Entities      []*Entity
}

type BQS

type BQS struct {
	World       *World
	PlayerMap   map[string]*Player
	ZoneMap     map[string]*Zone
	PlayerCount int
	Logger      *log.Logger
}

func NewBQS

func NewBQS(cfg *Config) *BQS

func (*BQS) HandleConnection

func (b *BQS) HandleConnection(c *websocket.Conn)

func (*BQS) Listen

func (b *BQS) Listen()

func (*BQS) ToEchoHandler

func (b *BQS) ToEchoHandler() echo.HandlerFunc

type Character

type Character struct {
	Entity
	Orientation int
	MaxHP       int
	HP          int
	TargetId    int
}

func (*Character) HasFullHealth

func (c *Character) HasFullHealth() bool

func (*Character) RegenHealthBy

func (c *Character) RegenHealthBy(value int)

func (*Character) ResetMaxHP

func (c *Character) ResetMaxHP(maxHitPoints int)

func (*Character) SetTarget

func (c *Character) SetTarget(targetId int)

type CheckPoint

type CheckPoint struct {
	Id   int
	X, Y int
	W, H int
	S    int
}

func (*CheckPoint) GetRandomPosition

func (cp *CheckPoint) GetRandomPosition() (x, y int)

type Chest

type Chest struct {
	X, Y  int
	Items []int `json:"i"`
}

type ChestArea

type ChestArea struct {
	Id     int
	X, Y   int
	TX, TY int
	W, H   int
	Items  []int `json:"i"`
}

type Config

type Config struct {
	Host        string
	Port        int
	DebugLevel  string `json:"debug_level"`
	MapFilePath string `json:"map_filepath"`
}

func LoadConf

func LoadConf(confPath string) (*Config, error)

type Entity

type Entity struct {
	Id   int
	X, Y int
	Kind EntityType
}

func (*Entity) GetState

func (e *Entity) GetState() []interface{}

type EntityInterface

type EntityInterface interface {
	GetState() []interface{}
}

type EntityType

type EntityType struct {
	Id    int
	Name  string
	Class string
}

func GetEntityTypeByString

func GetEntityTypeByString(kind string) EntityType

type Event

type Event struct {
	Type     int
	PlayerID int
	Data     []interface{}
}

func AquireEvent

func AquireEvent(t int, data ...interface{}) *Event

func (*Event) ToBytes

func (event *Event) ToBytes() ([]byte, error)

type Item

type Item struct {
	Entity
	IsStatic  bool
	Blink     bool
	IsDestroy bool
}

func NewDropItem

func NewDropItem(kind EntityType, x, y int) *Item

func NewItem

func NewItem(id int, kind EntityType, x, y int) *Item

func (*Item) DeswapnLater

func (i *Item) DeswapnLater(eventCh chan *Event)

func (*Item) ReswapnLater

func (i *Item) ReswapnLater(eventCh chan *Event)

type Map

type Map struct {
	Width, Height  int
	TileSize       int
	Collisions     []int
	Tilesize       int
	Grid           [][]bool
	CheckPoints    []CheckPoint
	ChestAreas     []ChestArea
	StaticChests   []Chest
	MobAreas       []MobArea `json:"roamingAreas"`
	StaticEntities map[string]string

	GroupWidth  int
	GroupHeight int
	ZoneWidth   int
	ZoneHeight  int

	CheckPointsMap map[int]*CheckPoint
	StartingAreas  []*CheckPoint
}

func LoadMap

func LoadMap(filename string) (*Map, error)

func (*Map) GetGroupIdFromPosition

func (m *Map) GetGroupIdFromPosition(x, y int) string

func (*Map) GetRandomStartingPosition

func (m *Map) GetRandomStartingPosition() (int, int)

func (*Map) InitMap

func (m *Map) InitMap() error

func (*Map) IsColliding

func (m *Map) IsColliding(x, y int) bool

func (*Map) IsOutOfBounds

func (m *Map) IsOutOfBounds(x, y int) bool

func (*Map) IsValidPosition

func (m *Map) IsValidPosition(x, y int) bool

func (Map) String

func (m Map) String() string

func (*Map) TileIndexToGridPosition

func (m *Map) TileIndexToGridPosition(tileNum int) (x, y int)

type Mob

type Mob struct {
	Character
	OriginX, OriginY        int
	ArmorLevel, WeaponLevel int
	Haters                  map[int]int
	IsDead                  bool
	ReswapnTimer            *time.Timer
	HateTimer               *time.Timer
	EventCh                 chan *Event
}

func NewMob

func NewMob(mobCount int, kind EntityType, x, y int) *Mob

func (*Mob) AddHate

func (m *Mob) AddHate(playerId, dmg int)

func (*Mob) ChaseTarget

func (mob *Mob) ChaseTarget(zoneId string, mp *Map, targetX, targetY int)

func (*Mob) ChooseMobTarget

func (m *Mob) ChooseMobTarget() int

func (*Mob) DropItem

func (m *Mob) DropItem() *Item

func (*Mob) GetState

func (m *Mob) GetState() []interface{}

func (*Mob) RecoveryHP

func (mob *Mob) RecoveryHP()

func (*Mob) ResetHateLater

func (mob *Mob) ResetHateLater(eventCh chan *Event)

func (*Mob) ReswapnLater

func (mob *Mob) ReswapnLater(eventCh chan *Event)

func (*Mob) SetEventCh

func (mob *Mob) SetEventCh(evenCh chan *Event)

type MobArea

type MobArea struct {
	Id            int
	X, Y          int
	Width, Height int
	Type          string
	NB            int
	Entities      []*Entity
}

type MobProperty

type MobProperty struct {
	Name   string
	Drops  map[string]int
	HP     int
	Armor  int
	Weapon int
}

func GetMobProperty

func GetMobProperty(kind EntityType) *MobProperty

type NPC

type NPC struct {
	Entity
}

func NewNPC

func NewNPC(kind EntityType, x, y int) *NPC

func (*NPC) GetState

func (npc *NPC) GetState() []interface{}

type Packet

type Packet struct {
	Type int
	Data []byte
	Err  error
}

type Player

type Player struct {
	Character
	Armor, Weapon           int
	ArmorLevel, WeaponLevel int
	Name                    string

	Orientation int

	EventCh    chan *Event
	PacketChan chan *Packet
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(conn *websocket.Conn, world *World) *Player

func (*Player) GetState

func (p *Player) GetState() []interface{}

func (*Player) HandleCmd

func (p *Player) HandleCmd(cmd int, args *simplejson.Json)

func (*Player) HandleLoop

func (p *Player) HandleLoop()

type World

type World struct {
	Map         *Map
	IdCh        chan int
	ZonesMap    map[string]*Zone
	BroadcastCh chan *Event

	Logger *log.Logger
	// contains filtered or unexported fields
}

func NewWrold

func NewWrold(cfg *Config) *World

func (*World) AddPlayer

func (w *World) AddPlayer()

func (*World) GetStartPosition

func (w *World) GetStartPosition(p *Player) (int, int)

func (*World) GetZoneChannelFromPosition

func (w *World) GetZoneChannelFromPosition(x, y int) chan *Event

func (*World) GetZoneIdFromPosition

func (w *World) GetZoneIdFromPosition(x, y int) string

func (*World) IsValidPosition

func (w *World) IsValidPosition(x, y int) bool

func (*World) RemovePlayer

func (w *World) RemovePlayer()

func (*World) Stop

func (w *World) Stop()

type Zone

type Zone struct {
	ID     string
	ZX, ZY int
	Map    *Map

	PlayersMap    map[int]*Player
	ItemsMap      map[int]*Item
	MobsMap       map[int]*Mob
	EntitiesIndex map[int]string
	NPCMap        map[int]*NPC
	EventCh       chan *Event
	Incoming      []int

	Logger *log.Logger
	// contains filtered or unexported fields
}

func NewZone

func NewZone(zx, zy int, bch chan *Event, ech chan struct{}, m *Map, logger *log.Logger) *Zone

func (*Zone) HandleEvent

func (z *Zone) HandleEvent(e *Event)

func (*Zone) Run

func (z *Zone) Run()

Jump to

Keyboard shortcuts

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