Something went wrong. Try again.
A very rough prototype kag tutorial rework
Something went wrong. Try again.
3.1 kB · 156 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
//////////////////////////// EventSectors////// This script will allow you to set up sectors and do events/// Check Test.as for use examples
#include "EventMixin"
class SectorEvent : Event { // Map sector, we don't want external sources messing with this private CMap::Sector@ EventSector;
// An id is needed, we cant use Sector ownerid unless you // want sectors to go when a blob despawns randomly u16 Id = 0;
// TODO: Check if topLeft & topRight are in wrong places (otherwise barrier wont spawn)
SectorEvent(EventFunc@ mainEvent, PreEventCheck@ checkEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) { @EventSector = getMap().server_AddSector(topLeft, botRight, Id + ''); Event(mainEvent, checkEvent, removeAfterUse); }
SectorEvent(EventFunc@ mainEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) { this = SectorEvent(mainEvent, null, topLeft, botRight, removeAfterUse); }
void SetNewSector(CMap::Sector@ newSector, bool removeOld = true) { if (removeOld && EventSector !is null) RemoveSector();
@EventSector = newSector; }
const CMap::Sector@ getSector() { return EventSector; }
void ChangeId(const u16 newId) { EventSector.name = newId+''; Id = newId; }
void RemoveSector() { getMap().RemoveSectorsAtPosition(EventSector.center, EventSector.name); }};
class SectorHandler{ array<SectorEvent@> EventList; CMap@ map;
SectorHandler() { @map = getMap(); } void AddNewEvent(SectorEvent@ newEvent) { if (newEvent !is null) { newEvent.ChangeId(EventList.length); EventList.push_back(newEvent); } }
void PushBack(SectorEvent@ newEvent) { AddNewEvent(newEvent); }
void Clear() { EventList.clear(); }
// Make sure you call RepairIndex's after void RemoveNoRepair(int index) { if (index < EventList.length) { EventList[index].RemoveSector(); EventList.erase(index); } }
void Remove(int index) { if (index < EventList.length) { EventList[index].RemoveSector(); EventList.erase(index);
RepairIndexIds(); } }
// Stop's a common crash void Reverse(int newSize) { if (EventList.length > 0) { EventList.reverse(); RepairIndexIds(); } }
void RepairIndexIds() { for (u16 a = 0; a < EventList.length; a++) { EventList[a].ChangeId(a); } }
void OnTick(CBlob@ blob) { CMap::Sector@[] sectors;
// Returns true if sectors are found if (map.getSectorsAtPosition(blob.getPosition(), @sectors)) { for(int a = 0; a < sectors.length; a++) { u16 id = parseInt(sectors[a].name); SectorEvent@ event = EventList[id]; // Returns true if we should destroy after calling if (event.CheckAndEvent(blob)) Remove(id); } } }
void Destroy() { for (int a = 0; a < EventList.length; a++) { if (EventList[a] !is null) { EventList[a].RemoveSector(); } } }};