Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Set race on character creation #6

Merged
merged 1 commit into from
Jan 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions app/eoceneServices/Validator.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/**
* *****************************************************************************
* Copyright (c) 2014 Christian Garbers.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Simplified BSD License
* which accompanies this distribution
*
* Contributors:
* Christian Garbers - initial API and implementation
* ****************************************************************************
/*
* Copyright (c) 2016 Christian Garbers.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Simplified BSD License
* which accompanies this distribution
* Contributors:
* Christian Garbers - initial API and implementation
*/
package eoceneServices

Expand Down Expand Up @@ -99,7 +96,7 @@ class Validator(char: models.Character) {
def eligableForCircle(circle: Int, discipline: models.Discipline): Boolean = {
val talentsOdiscipline = char.talents.
filter(talent => talent.step.isDefined).
filter(talent => talent.disciplineId.get == discipline.id)
filter(talent => talent.disciplineId.getOrElse(0) == discipline.id)
val nrTalents = talentsOdiscipline.size >= circleRequiremnents(circle)._1
val minRank = talentsOdiscipline.count(talent => talent.step.getOrElse(0) >= circle) >= circleRequiremnents(circle)._2
val singleTalent = talentsOdiscipline.
Expand Down
115 changes: 62 additions & 53 deletions app/eoceneServices/eoceneSqlService.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (c) 2016 Christian Garbers.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Simplified BSD License
* which accompanies this distribution
* Contributors:
* Christian Garbers - initial API and implementation
*/

package eoceneServices

import anorm._
Expand Down Expand Up @@ -137,11 +146,12 @@ class eoceneSqlService extends eoceneDao{
DB.withTransaction("chars") { implicit c =>
val result: Boolean = SQL(eoceneSqlStrings.INSERT_CHAR).onParams(name).
executeUpdate() > 0
val char_id = getCharIdByName(name)
eoceneSqlStrings.INSERT_CHARS_USERS.onParams(char_id,
val charId = getCharIdByName(name)
changeCharRace(charId.getOrElse(0), 1)
eoceneSqlStrings.INSERT_CHARS_USERS.onParams(charId,
user.main.userId).execute()
eoceneUserService.updateUsersChars()
char_id
charId
}
}

Expand Down Expand Up @@ -400,35 +410,6 @@ class eoceneSqlService extends eoceneDao{
}
}

/**
* Remove one circle (or forget)
*
* @param id the id of the character
* @param id_talent
* @return success
*/
def corruptCharTalent(id: Int, id_talent: Int): Boolean = {
val talents = getCharTalentRowsIdByCharId(id)
val target_talent = talents.filter(a => a(1) == id_talent)
if (target_talent.size == 0) return false
val circle = getTalentCircleByTalenAndDisciId(id_talent, id)
val step = target_talent(0)(2)
val lp_cost = eoceneServices.utilities.getTalentCost(step, circle)
DB.withTransaction("chars"){implicit c=>
if (step > 1) {
SQL(eoceneSqlStrings.UPDATE_CHAR_TALENT).onParams(step - 1, id,
id_talent).executeUpdate() > 0
SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id)
.executeUpdate() > 0
} else {
SQL(eoceneSqlStrings.REMOVE_CHAR_TALENT).onParams(id, id_talent)
.executeUpdate() > 0
SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id)
.executeUpdate() > 0
}
}
}

/**
* Get data for talents of a charcter
*
Expand All @@ -438,12 +419,11 @@ class eoceneSqlService extends eoceneDao{
* respectively
*/
def getCharTalentRowsIdByCharId(id: Int): List[List[Int]] = {
DB.withConnection("chars") { implicit c =>
{
val querry = SQL(eoceneSqlStrings.GET_CHAR_TALENTS).onParams(id)()
return querry.map(a => List(a[Int]("id_char"), a[Int]("id_talent"),
a[Int]("step"))).toList
}
DB.withConnection("chars") { implicit c => {
val querry = SQL(eoceneSqlStrings.GET_CHAR_TALENTS).onParams(id)()
return querry.map(a => List(a[Int]("id_char"), a[Int]("id_talent"),
a[Int]("step"))).toList
}
}
}

Expand All @@ -463,6 +443,35 @@ class eoceneSqlService extends eoceneDao{
}
}

/**
* Remove one circle (or forget)
*
* @param id the id of the character
* @param id_talent
* @return success
*/
def corruptCharTalent(id: Int, id_talent: Int): Boolean = {
val talents = getCharTalentRowsIdByCharId(id)
val target_talent = talents.filter(a => a(1) == id_talent)
if (target_talent.size == 0) return false
val circle = getTalentCircleByTalenAndDisciId(id_talent, id)
val step = target_talent(0)(2)
val lp_cost = eoceneServices.utilities.getTalentCost(step, circle)
DB.withTransaction("chars") { implicit c =>
if (step > 1) {
SQL(eoceneSqlStrings.UPDATE_CHAR_TALENT).onParams(step - 1, id,
id_talent).executeUpdate() > 0
SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id)
.executeUpdate() > 0
} else {
SQL(eoceneSqlStrings.REMOVE_CHAR_TALENT).onParams(id, id_talent)
.executeUpdate() > 0
SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id)
.executeUpdate() > 0
}
}
}

/**
* Improve a skill (or learn it)
*
Expand Down Expand Up @@ -720,21 +729,6 @@ class eoceneSqlService extends eoceneDao{
}
}

/**
* Spent Karma points
*
* @param id_char
* @param nr_points the number of karma points spent
* @return Redirect
*/
def spentKarma(id_char: Int, nr_points: Int) = {
DB.withConnection("chars"){implicit c=>
val char = getCharById(id_char)
SQL(eoceneSqlStrings.UPDATE_CHAR_ATTRIBUTE.format("kar_curr"))
.onParams(char.get.karCurr - nr_points, id_char).executeUpdate > 0
}
}

/**
* Get the id of a character with a certain name
*
Expand Down Expand Up @@ -945,6 +939,21 @@ class eoceneSqlService extends eoceneDao{
row[Option[Int]]("chars_disciplines.circle"), modifiers)
}

/**
* Spent Karma points
*
* @param id_char
* @param nr_points the number of karma points spent
* @return Redirect
*/
def spentKarma(id_char: Int, nr_points: Int) = {
DB.withConnection("chars") { implicit c =>
val char = getCharById(id_char)
SQL(eoceneSqlStrings.UPDATE_CHAR_ATTRIBUTE.format("kar_curr"))
.onParams(char.get.karCurr - nr_points, id_char).executeUpdate > 0
}
}

/**
* Adding legend points
*
Expand Down
12 changes: 3 additions & 9 deletions app/models/Skill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contributors:
* Christian Garbers - initial API and implementation
*/

package models


Expand Down Expand Up @@ -37,15 +38,8 @@ case class Skill(val id: Int, val name: String, val formula: String,
step match {
case None => 0 //in case we have no step rank is not defined
case _ => //First we do the formula attribute conversion
val rank = formulaSplit(0) match {
case "Dex" => char.derived("dex_step").asInstanceOf[Int] + step.getOrElse(0)
case "Str" => char.derived("str_step").asInstanceOf[Int] + step.getOrElse(0)
case "Tou" => char.derived("tou_step").asInstanceOf[Int] + step.getOrElse(0)
case "Cha" => char.derived("cha_step").asInstanceOf[Int] + step.getOrElse(0)
case "Per" => char.derived("dex_step").asInstanceOf[Int] + step.getOrElse(0)
case "Wil" => char.derived("wil_step").asInstanceOf[Int] + step.getOrElse(0)
case _ => 0
}
val rank = char.derived(formulaSplit(0).toLowerCase() + "_step")
.asInstanceOf[Int] + step.getOrElse(0)
//return the derived rank or add the second part of formula
formulaSplit.size match {
case 1 => rank
Expand Down