Esempio n. 1
0
func (gen RoomsGenerator) addDoorGuard(room *g.Room, location *g.Location, doorDirect g.DoorDirect) {
	var posMonster g.PosObj

	middleX := location.SizeX / 2
	middleY := location.SizeY / 2

	switch doorDirect {
	case g.DoorUp:
		posMonster = *g.NewPosObj(location, middleX, 1)
	case g.DoorDown:
		posMonster = *g.NewPosObj(location, middleX, location.SizeY-2)
	case g.DoorLeft:
		posMonster = *g.NewPosObj(location, 1, middleY)
	case g.DoorRight:
		posMonster = *g.NewPosObj(location, location.SizeX-2, middleY)
	default:
		panic("unknow DoorDirect")
	}

	monster := g.CreateRandomMonster(g.MonPirate, g.MonFastGoblin, g.MonSlyGoblin, g.MonSkeleton, g.MonGhost)
	monster.PosObj = posMonster

	if monster.TypeName == g.MonPirate {
		monster.Drops = &g.CustomItem{TypeName: "rum", Name: "бутылка рома", Usable: true}
	}

	room.AddMonster(monster)
}
Esempio n. 2
0
func (gen RoomsGenerator) addWaterScroll(room *g.Room, location *g.Location) {
	room.AddItem(
		&g.PlaceItem{
			PosObj: *g.NewPosObj(location, location.SizeX-2, location.SizeY-2),
			Item:   g.FactoryWeapons["WaterScroll"](),
		},
	)
}
Esempio n. 3
0
func (gen RoomsGenerator) addKeyToLocation(room *g.Room, location *g.Location) {
	key := g.CustomItem{TypeName: "golden-key", Name: "золотой ключ"}
	room.AddItem(
		&g.PlaceItem{
			PosObj: *g.NewPosObj(location, location.SizeX-2, location.SizeY-2),
			Item:   &key,
		},
	)
}
Esempio n. 4
0
func (gen RoomsGenerator) markLocationAsFinish(room *g.Room, location *g.Location) {
	cellsCount := len(location.CellsMap)
	idx := cellsCount / 2
	location.CellsMap[idx] = "&"
	triggerX, triggerY := g.CellIdxToXY(idx, location.SizeX)
	exitTrigger := g.CreateExitTrigger(*g.NewPosObj(location, triggerX, triggerY))
	room.AddTrigger(exitTrigger)
	room.ExitLocationID = location.RefID()
}
Esempio n. 5
0
func (gen RoomsGenerator) NewRoom() *g.Room {
	room := g.NewRoom()
	mapSizeX, mapSizeY := mapSize, mapSize
	mapDoors := gen.newMapDoors(mapSizeX, mapSizeY)

	mapLocations := make([][]*g.Location, mapSizeY)
	{
		locationCells := make([]*g.Location, mapSizeX*mapSizeY)
		for i := range mapLocations {
			mapLocations[i], locationCells = locationCells[:mapSizeX], locationCells[mapSizeX:]
		}
	}

	for y, row := range mapDoors {
		for x, _ := range row {
			location := gen.newLocation()
			mapLocations[x][y] = location
			room.AddLocation(location)
		}
	}

	gen.addDoorsForLocations(room, mapLocations, mapDoors)

	locations := room.GetLocations()
	room.StartLocationID = locations[0].RefID()

	finishLocation := locations[locations.Count()-1]
	gen.markLocationAsFinish(room, finishLocation)

	{
		ifritLocation := locations[rand.Intn(locations.Count())]
		ifrit := g.FactoryMonsters[g.MonIfrit]()
		ifrit.PosObj = g.PosObj{LocationID: ifritLocation.RefID(), PosX: ifritLocation.SizeX - 2, PosY: 1}
		ifrit.Drops = &g.CustomItem{TypeName: "golden-key", Name: "золотой ключ"}
		room.AddMonster(ifrit)
	}

	{
		maceLocation := locations[rand.Intn(locations.Count())]
		room.AddItem(
			&g.PlaceItem{
				PosObj: *g.NewPosObj(maceLocation, maceLocation.SizeX-2, maceLocation.SizeY-2),
				Item:   g.FactoryWeapons["LongSword"](),
			},
		)
	}

	waterScrollLocation := locations[rand.Intn(locations.Count())]
	gen.addWaterScroll(room, waterScrollLocation)

	//keyLocationX, keyLocationY := rand.Intn(mapSizeX), rand.Intn(mapSizeY)
	//keyLocation := locations[keyLocationY * mapSizeX + keyLocationX]
	//gen.addKeyToLocation(room, finishLocation)

	return room
}
Esempio n. 6
0
func (gen RoomsGenerator) addDoorsForLocations(room *g.Room, mapLocations [][]*g.Location, mapDoors [][]string) {
	for rowN, row := range mapLocations {
		for colN, location := range row {
			doors := mapDoors[rowN][colN]

			middleX := location.SizeX / 2
			middleY := location.SizeY / 2

			var triggerX, triggerY int
			var targetPos g.PosObj

			if strings.Contains(doors, "L") {
				doorIdx := gen.doorLocationIdx(location, g.DoorLeft)
				location.CellsMap[doorIdx] = "<"
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN][colN-1], location.SizeX-1, middleY)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorLeft)
				gen.addDoorGuard(room, location, g.DoorLeft)
			}
			if strings.Contains(doors, "R") {
				doorIdx := gen.doorLocationIdx(location, g.DoorRight)
				location.CellsMap[doorIdx] = ">"
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN][colN+1], 0, middleY)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorRight)
				gen.addDoorGuard(room, location, g.DoorRight)
			}
			if strings.Contains(doors, "U") {
				doorIdx := gen.doorLocationIdx(location, g.DoorUp)
				location.CellsMap[doorIdx] = `/\`
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN-1][colN], middleX, location.SizeY-1)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorUp)
				gen.addDoorGuard(room, location, g.DoorUp)
			}
			if strings.Contains(doors, "D") {
				doorIdx := gen.doorLocationIdx(location, g.DoorDown)
				location.CellsMap[doorIdx] = `\/`
				triggerX, triggerY = g.CellIdxToXY(doorIdx, location.SizeX)
				targetPos = *g.NewPosObj(mapLocations[rowN+1][colN], middleX, 0)
				gen.addDoorTrigger(room, *g.NewPosObj(location, triggerX, triggerY), targetPos, g.DoorDown)
				gen.addDoorGuard(room, location, g.DoorDown)
			}
		}
	}

}