Пример #1
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*Player)
		actions := make(Actions)
		p.Entity.AddComponent(actions)
	})

	event.On(event.PlayerQuery, func(args ...interface{}) {
		p := args[0].(*Player)
		actions := p.Entity.Component(COMP_Actions).(Actions)
		actions.QueryPlayer(p.Username)
	})

	event.On(event.PlayerInsert, func(args ...interface{}) {
		p := args[0].(*Player)
		actions := p.Entity.Component(COMP_Actions).(Actions)
		actions.InsertPlayer(p.Username)
	})

	event.On(event.PlayerDelete, func(args ...interface{}) {
		p := args[0].(*Player)
		actions := p.Entity.Component(COMP_Actions).(Actions)
		actions.DeletePlayer(p.Username)
	})

	event.On(event.BindingDown, func(args ...interface{}) {
		p := args[0].(*Player)
		binding := args[1].(*Binding)

		if binding.SpellId > 0 {
			p.Entity.Component(COMP_Actions).(Actions).Cast(binding)
		}
	})
}
Пример #2
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*Player)
		location := MakeLocation(&space.Rect{})
		p.Entity.AddComponent(location)
	})
	event.On(event.PlayerQuery, func(args ...interface{}) {
		p := args[0].(*Player)
		location := p.Entity.Component(COMP_Location).(*Location)
		location.QueryPlayer(p.Username)

		if class, _ := GetClass(p.Class); class != nil {
			r := location.Shape.(*space.Rect)
			r.Dimension.DX = Classes[p.Class].Dimension.DX
			r.Dimension.DY = Classes[p.Class].Dimension.DY
		}
	})
	event.On(event.EntityQuery, func(args ...interface{}) {
		e := args[0].(*Entity)
		universeId := args[1].(uint)

		location := MakeLocation(&space.Rect{})
		if err := location.QueryEntityUniverse(e.Id, universeId); err == nil {
			e.AddComponent(location)
		}
	})
	event.On(event.PlayerInsert, func(args ...interface{}) {
		p := args[0].(*Player)

		location := p.Entity.Component(COMP_Location).(*Location)
		location.InsertPlayer(p.Username)
	})
}
Пример #3
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*Player)
		bag := MakeBag(p.BagSize)

		p.Entity.AddComponent(bag)
	})

	event.On(event.PlayerQuery, func(args ...interface{}) {
		p := args[0].(*Player)
		bag := p.Entity.Component(COMP_Bag).(*Bag)
		bag.QueryPlayer(p.Username)
	})

	event.On(event.PlayerInsert, func(args ...interface{}) {
		p := args[0].(*Player)
		bag := p.Entity.Component(COMP_Bag).(*Bag)
		bag.InsertPlayer(p.Username)
	})

	event.On(event.PlayerDelete, func(args ...interface{}) {
		p := args[0].(*Player)
		bag := p.Entity.Component(COMP_Bag).(*Bag)
		bag.DeletePlayer(p.Username)
	})

	event.On(event.BindingDown, func(args ...interface{}) {
		p := args[0].(*Player)
		binding := args[1].(*Binding)

		if binding.BagSlot > 0 {
			p.Entity.Component(COMP_Bag).(*Bag).Cast(binding)
		}
	})
}
Пример #4
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*Player)
		bindings := make(Bindings)

		p.Entity.AddComponent(bindings)
	})

	event.On(event.PlayerQuery, func(args ...interface{}) {
		p := args[0].(*Player)
		bindings := p.Entity.Component(COMP_Bindings).(Bindings)
		bindings.QueryPlayer(p.Username)

		if len(bindings) == 0 {
			for key, binding := range MakeBindingsDefault() {
				bindings[key] = binding
			}
		}
	})

	event.On(event.PlayerInsert, func(args ...interface{}) {
		p := args[0].(*Player)
		bindings := p.Entity.Component(COMP_Bindings).(Bindings)
		bindings.InsertPlayer(p.Username)
	})

	event.On(event.PlayerDelete, func(args ...interface{}) {
		p := args[0].(*Player)
		bindings := p.Entity.Component(COMP_Bindings).(Bindings)
		bindings.DeletePlayer(p.Username)
	})
}
Пример #5
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*Player)
		animations := make(Animations)
		p.Entity.AddComponent(animations)
	})

	event.On(event.PlayerQuery, func(args ...interface{}) {
		p := args[0].(*Player)
		animations := p.Entity.Component(COMP_Animations).(Animations)

		if c, err := GetClass(p.Class); c != nil {
			animations.clear()
			for key, value := range c.Animations {
				animations[key] = value
			}
			p.Entity.Image = c.Animations["portrait"]
		} else {
			logrus.WithFields(logrus.Fields{
				"Username": p.Username,
				"Class":    p.Class,
			}).Warn("save.Animations: " + err.Error())
		}
	})

	event.On(event.MovementUpdate, func(args ...interface{}) {
		e := args[0].(*Entity)
		v, ok := args[1].(*space.Vector)

		animations, ok := e.Component(COMP_Animations).(Animations)

		if !ok {
			return
		}

		if v == nil {
			e.Image = animations["portrait"]
		} else if slope := v.AsSlope(); slope == math.Inf(-1) {
			e.Image = animations["walk-up"]
		} else if slope == math.Inf(1) {
			e.Image = animations["walk-down"]
		} else if v.DX > 0 {
			e.Image = animations["walk-right"]
		} else {
			e.Image = animations["walk-left"]
		}
	})
}
Пример #6
0
func init() {
	event.On(event.EntityQuery, func(args ...interface{}) {
		e := args[0].(*Entity)
		universeId := args[1].(uint)

		comp := &ItemSlot{}
		if err := comp.QueryEntityUniverse(e.Id, universeId); err != nil {
			logrus.WithFields(logrus.Fields{
				"Entity":   e.Id,
				"Universe": universeId,
			}).Error("save.ItemSlot(entity): " + err.Error())
			return
		}

		e.AddComponent(comp)
		if item, err := GetItem(comp.Item); item != nil {
			e.Image = item.Image
		} else if err != nil {
			logrus.WithFields(logrus.Fields{
				"Entity":   e.Id,
				"Universe": universeId,
				"Item":     comp.Item,
			}).Error("save.ItemSlot(item): " + err.Error())
		}
	})
}
Пример #7
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*save.Player)
		menus := &Menus{}

		p.Entity.AddComponent(menus)
	})

	event.On(event.BindingDown, func(args ...interface{}) {
		p := args[0].(*save.Player)
		b := args[1].(*save.Binding)

		if strings.HasPrefix(b.SystemId, "menu") {
			m := p.Entity.Component(COMP_Menus).(*Menus)
			m.Toggle(b.SystemId[5:])
		}
	})
}
Пример #8
0
func init() {
	event.On(event.AccountMake, func(args ...interface{}) {
		p := MakePlayer(args[0].(*Account).Username)
		Players[p.Username] = p
	})
	event.On(event.AccountQuery, func(args ...interface{}) {
		p := Players[args[0].(*Account).Username]
		p.Query()
	})
	event.On(event.AccountInsert, func(args ...interface{}) {
		p := Players[args[0].(*Account).Username]
		p.Insert()
	})
	event.On(event.AccountDelete, func(args ...interface{}) {
		p := Players[args[0].(*Account).Username]
		p.Delete()
	})
}
Пример #9
0
func init() {
	event.On(event.PlayerMake, func(args ...interface{}) {
		p := args[0].(*save.Player)
		m := &Movement{}
		p.Entity.AddComponent(m)
	})
	event.On(event.BindingDown, func(args ...interface{}) {
		p := args[0].(*save.Player)
		b := args[1].(*save.Binding)

		if strings.HasPrefix(b.SystemId, "walk") {
			p.Entity.Component(COMP_Movement).(*Movement).Walk(b.SystemId[5:])
		}
	})
	event.On(event.BindingUp, func(args ...interface{}) {
		p := args[0].(*save.Player)
		b := args[1].(*save.Binding)

		if strings.HasPrefix(b.SystemId, "walk") {
			p.Entity.Component(COMP_Movement).(*Movement).ClearWalk(b.SystemId[5:])
		}
	})
}
Пример #10
0
func init() {
	event.On(event.UniverseQuery, func(args ...interface{}) {
		u := args[0].(*Universe)
		entities := make(Entities)

		if err := entities.QueryUniverse(u.Id); err != nil {
			logrus.WithFields(logrus.Fields{
				"Universe": u.Id,
			}).Error("save.Entity: " + err.Error())
		}

		for _, entity := range entities {
			u.Add(entity)
		}
	})
}
Пример #11
0
func init() {
	event.On(event.MovementCollision, func(args ...interface{}) {
		entity1 := args[0].(*save.Entity)
		entity2 := args[1].(*save.Entity)
		u := args[2].(*save.Universe)

		bag, ok := entity1.Component(save.COMP_Bag).(*save.Bag)
		if !ok {
			return
		}

		addslot, ok := entity2.Component(save.COMP_ItemSlot).(*save.ItemSlot)
		if !ok {
			return
		}

		if bag.Add(addslot) {
			u.Remove(entity2)
		}
	})
}