forked from ironarachne/world
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API endpoints for language and pantheons
- Loading branch information
Ben Overmyer
committed
Apr 25, 2019
1 parent
9c10341
commit 363dda1
Showing
4 changed files
with
129 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package pantheon | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/ironarachne/world/pkg/random" | ||
) | ||
|
||
// Deity is a fictional god or goddess | ||
type Deity struct { | ||
Name string | ||
Domains []Domain | ||
Appearance string | ||
Gender string | ||
PersonalityTraits []string | ||
} | ||
|
||
// GenerateDeity generates a random deity | ||
func (pantheon Pantheon) GenerateDeity() Deity { | ||
var deity Deity | ||
var domain Domain | ||
var allDomains []Domain | ||
|
||
domains := getAllDomains() | ||
|
||
numberOfDomains := rand.Intn(3) + 1 | ||
|
||
for _, deity := range pantheon.Deities { | ||
for _, d := range deity.Domains { | ||
allDomains = append(allDomains, d) | ||
} | ||
} | ||
|
||
for i := 0; i < numberOfDomains; i++ { | ||
domain = getRandomDomain(domains) | ||
|
||
// Only add domain if it isn't already in Domains slice | ||
if !isDomainInSlice(domain, deity.Domains) && !isDomainInSlice(domain, allDomains) { | ||
deity.Domains = append(deity.Domains, domain) | ||
allDomains = append(allDomains, domain) | ||
} | ||
} | ||
|
||
appearances := getRandomGeneralAppearances(3) | ||
appearances = append(appearances, getAllAppearancesForDomains(deity.Domains)...) | ||
|
||
deity.Appearance = random.String(appearances) | ||
deity.Gender = getRandomGender() | ||
|
||
deity.PersonalityTraits = deity.getRandomTraits() | ||
|
||
deity.Name = pantheon.Language.RandomName() | ||
|
||
return deity | ||
} | ||
|
||
func getRandomGender() string { | ||
genders := map[string]int{ | ||
"female": 6, | ||
"male": 5, | ||
"none": 1, | ||
} | ||
|
||
return random.StringFromThresholdMap(genders) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters